Google News
logo
C++ Program to Find Quotient and Remainder
In the following example of C++ program that calculates the quotient and remainder of two numbers entered by the user :
Program :
#include <iostream>

int main() {
    int dividend, divisor, 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;
}
Output :
Enter dividend: 17
Enter divisor: 4
Quotient = 4
Remainder = 1
* This program declares four variables: dividend, divisor, quotient, and remainder, which are all of type int.

* The program then prompts the user to enter two numbers using the std::cout and std::cin objects from the iostream library. The >> operator is used to input the user's numbers into the variables dividend and divisor.

* The program then calculates the quotient and remainder of the two numbers using the / and % operators, respectively.

* The quotient is stored in the quotient variable, and the remainder is stored in the remainder variable. Finally, the program uses std::cout to output messages that display the quotient and remainder to the console.