Loading...
C Program to Compute Quotient and Remainder

C Program to Compute Quotient and Remainder

In this example, we will learn to find the quotient and remainder when an integer is divided by another integer.

Remainder :

To understand this example, you must have the knowledge of the following C programming topics:


Program to Compute Quotient and Remainder

#include <stdio.h>

int main() {
  int dividend, divisor, quotient, remainder;
  printf("Enter dividend : ");
  scanf("%d", &dividend);
  printf("Enter divisor : ");
  scanf("%d", &divisor);
  quotient = dividend / divisor;
  remainder = dividend % divisor;
  printf("Quotient is %d and Remainder is %d", quotient, remainder);
  return 0;
}

Output

Enter dividend : 37
Enter divisor : 4
Quotient is 9 and Remainder is 1

Working of the above program

  • First we declare integer character variables dividend, divisor to store the value of dividend and divisor entered by the user and remainder, quotient to store the results.
  • int dividend, divisor, quotient, remainder;
  • Then we asked the user to enter dividend and take the user input using scanf() function and store the entered value in variable dividend.
  • printf("Enter dividend : ");
    scanf("%d", &dividend);
  • Then we asked the user to enter divisor and take the user input using scanf() function and store the entered value in variable divisor.
  • printf("Enter divisor : ");
    scanf("%d", &divisor);
  • Then we divide the dividend by divisor and store the value in quotient variable.
  • quotient = dividend / divisor;
  • Then we use the % modulus operator to get the remainder when we divide dividend with divisor.
  • remainder = dividend % divisor;
  • Finally we print the values of quotient and remainder using printf() function.
  • printf("Quotient is %d and Remainder is %d", quotient, remainder);

- Related Topics