This program declares four variables: dividend
and divisor
to hold the two integers entered by the user, and quotient
and remainder
to hold the quotient and remainder of the division, respectively. It then uses the cout
object to print prompts asking the user to enter the dividend and divisor, and the cin
object to read the numbers from the standard input stream. Finally, it calculates the quotient and remainder using the /
and %
operators, respectively, and prints the results using cout
.
I hope this helps! Let me know if you have any questions.
#include <iostream>
int main()
{
int dividend, divisor, quotient, remainder; // Declare variables to hold the dividend, divisor, quotient, and remainder
std::cout << "Enter the dividend: "; // Prompt the user to enter the dividend
std::cin >> dividend; // Read the dividend from the standard input stream
std::cout << "Enter the divisor: "; // Prompt the user to enter the divisor
std::cin >> divisor; // Read the divisor from the standard input stream
quotient = dividend / divisor; // Calculate the quotient
remainder = dividend % divisor; // Calculate the remainder
std::cout << "The quotient is: " << quotient << std::endl; // Print the quotient
std::cout << "The remainder is: " << remainder << std::endl; // Print the remainder
return 0;
}
Leave a Reply