C Program to Compute Quotient and Remainder
Program to Compute Quotient and Remainder
#include <stdio.h>
int main(){
int dividend, divisor, quotient, remainder;
printf("Enter dividend: ");
scanf("%d", ÷nd);
printf("Enter divisor: ");
scanf("%d", &divisor);
// Computes quotient
quotient = dividend / divisor;
// Computes remainder
remainder = dividend % divisor;
printf("Quotient = %d\n", quotient);
printf("Remainder = %d", remainder);
return 0;
}
Output
Enter dividend: 25 Enter divisor: 4 Quotient = 6 Remainder = 1
In this program, the user is asked to enter two integers (dividend and divisor) which are stored in variable dividend and divisor respectively.
Then the quotient is evaluated using division/operator and stored in the variable quotient.
Similarly, the remainder is evaluated using the modulus % operator and stored in a remainder variable.
Finally, the quotient and remainder are displayed using printf()
function.
C program that computes the quotient and remainder of two integers entered by the user:
#include <stdio.h>
int main() {
int dividend, divisor, quotient, remainder;
printf("Enter dividend: ");
scanf("%d", ÷nd);
printf("Enter divisor: ");
scanf("%d", &divisor);
quotient = dividend / divisor;
remainder = dividend % divisor;
printf("Quotient = %d\n", quotient);
printf("Remainder = %d\n", remainder);
return 0;
}
When you run this program, it will prompt the user to enter the dividend and divisor values. The program then calculates the quotient and remainder using the /
(division) and %
(modulus) operators, respectively. Finally, the program prints out the values of the quotient and remainder using the printf
function.
Note that if the divisor is zero, the program will result in a division by zero error.