Answers for "Take two integers, return the quotient and remainder, divmod"

0

Take two integers, return the quotient and remainder, divmod

//  Take two integers, return the quotient and remainder

#include <iostream>
using namespace std;

auto divmod(int dividend, int divisor) {
    struct result {int quotient; int remainder;};
    return result {dividend / divisor, dividend % divisor};
}

int main() {
    auto result = divmod(14, 3);
    cout << result.quotient << ", " << result.remainder << endl;

    // or

    auto [quotient, remainder] = divmod(14, 3);
    cout << quotient << ", " << remainder << endl;
}
Posted by: Guest on September-09-2021
0

Take two integers, return the quotient and remainder, divmod

//  Take two integers, return the quotient and remainder
fn divmod(dividend: isize, divisor: isize) -> (isize, isize) {
    (dividend / divisor, dividend % divisor)
}

fn main() {
    let (q, r) = divmod(14, 3);
    println!("divmod = quotient {}, remainder {} ", q, r);
}
Posted by: Guest on September-09-2021

Code answers related to "Take two integers, return the quotient and remainder, divmod"

Browse Popular Code Answers by Language