jhyatt1017
7/18/2018 - 3:37 AM

Compute quotient and remainder

#include <iostream>

int main()
{
    int divisor, dividend, quotient, remainder;

    std::cout << "Enter dividend: ";
    std::cin >> dividend;

    std::cout << "Enter divisor: ";
    std::cin >> divisor;

    quotient = dividend / divisor;
    remainder = dividend % divisor;

    std::cout << "Quotient = " << quotient << std::endl;
    std::cout << "Remainder = " << remainder;

    return 0;
}

In this program, user is asked to enter two integers (divisor and dividend) and computes the quotient and remainder.

  • To compute quotient and remainder, both divisor and dividend should be integers.

  • The division operator / is computes the quotient (either between float or integer variables).

  • The modulus operator % computes the remainder when one integer is divided by another (modulus operator cannot be used for floating-type variables).