take two integers 2c return the quotient and remainder 2c divmod

Solutions on MaxInterview for take two integers 2c return the quotient and remainder 2c divmod by the best coders in the world

showing results for - "take two integers 2c return the quotient and remainder 2c divmod"
Lorenzo
06 Jun 2018
1//  Take two integers, return the quotient and remainder
2fn divmod(dividend: isize, divisor: isize) -> (isize, isize) {
3    (dividend / divisor, dividend % divisor)
4}
5
6fn main() {
7    let (q, r) = divmod(14, 3);
8    println!("divmod = quotient {}, remainder {} ", q, r);
9}
Calista
10 Jul 2017
1//  Take two integers, return the quotient and remainder
2
3#include <iostream>
4using namespace std;
5
6auto divmod(int dividend, int divisor) {
7    struct result {int quotient; int remainder;};
8    return result {dividend / divisor, dividend % divisor};
9}
10
11int main() {
12    auto result = divmod(14, 3);
13    cout << result.quotient << ", " << result.remainder << endl;
14
15    // or
16
17    auto [quotient, remainder] = divmod(14, 3);
18    cout << quotient << ", " << remainder << endl;
19}
similar questions