Compute Quotient and Remainder in C

Exercise:

Write a C Program to compute quotient and remainder by performing division.

Click Here to View the Solution!
#include <stdio.h>
int main() {
    int dividend, divisor, quotient, remainder;
    printf("Enter dividend: ");
    scanf("%d", &dividend);

    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;
}
Click Here to View the Output!
Enter dividend: 8
Enter divisor: 3
Quotient = 2
Remainder = 2
Click Here to View the Explanation!
  • This program is used to calculate and print the quotient and remainder of two numbers.
  • In the main method, the program requests the user to enter two values. A dividend and a divisor.
  • The dividend is divided by the divisor using the / operator and their result is store in an integer variable quotient.
  • The remainder of the dividend and divisor is calculated using the % modulus operator and the result is stored in the integer variable remainder.
  • Both the quotient and remainder are printed on the screen using the printf() functions.
  • The return 0 statement ends the program.

%d bloggers like this: