How does a C program to compute quotient and remainder work?
Courtesy: Programiz.com
In this program, the user is asked to enter two integers (dividend and divisor). They are stored in variables dividend and divisor respectively.
printf("Enter dividend: ");
scanf("%d", ÷nd);
printf("Enter divisor: ");
scanf("%d", &divisor);
Then the quotient is evaluated using / (the division operator), and stored in quotient.
quotient = dividend / divisor;
Similarly, the remainder is evaluated using % (the modulo operator) and stored in remainder.
remainder = dividend % divisor;
Finally, the quotient and remainder are displayed using printf().
printf("Quotient = %d\n", quotient);
printf("Remainder = %d", remainder);
Comments
Post a Comment