## C Program to Find Quotient and Remainder

June 5, 2021 Program to find quotient and remainder based on the dividend & divisor values entered by user.

## Example 1: Program to find Quotient and Remainder

In this program, user is asked to enter the dividend and divisor and the program then finds the quotient and remainder based on the input values.

```#include <stdio.h>
int main(){
int num1, num2, quot, rem;

printf("Enter dividend: ");
scanf("%d", &num1);

printf("Enter divisor: ");
scanf("%d", &num2);

/* The "/" Arithmetic operator returns the quotient
* Here the num1 is divided by num2 and the quotient
* is assigned to the variable quot
*/
quot = num1 / num2;

/* The modulus operator "%" returns the remainder after
* dividing num1 by num2.
*/
rem = num1 % num2;

printf("Quotient is: %d\n", quot);
printf("Remainder is: %d", rem);

return 0;
}```

Output:

```Enter dividend: 15
Enter divisor: 2
Quotient is: 7
Remainder is: 1```

## Example 2: Program to find Quotient and Remainder using function

In this program, we are doing the same thing that we have done in the above program, but here we are using functions in order to find the quotient and remainder. We have created two user defined functions for the calculation. To understand this program, you should have the basic understanding of following C programming topics:

1. Functions in C
2. Function call by value in C
```#include <stdio.h>
// Function to computer quotient
int quotient(int a, int b){
return a / b;
}

// Function to computer remainder
int remainder(int a, int b){
return a % b;
}

int main(){
int num1, num2, quot, rem;
printf("Enter dividend: ");
scanf("%d", &num1);
printf("Enter divisor: ");
scanf("%d", &num2);

//Calling function quotient()
quot = quotient(num1, num2);

//Calling function remainder()
rem = remainder(num1, num2);
printf("Quotient is: %d\n", quot);
printf("Remainder is: %d", rem);
return 0;
}```