Table of Contents
Program to Compute Quotient and Remainder in C
In this tutorial, we will discuss the Program to Compute Quotient and Remainder in C
In this post, we are going to learn how to find quotient and remainder using two numbers via different 3 ways in C.
Compute Quotient and Remainder
Compute Quotient and Remainder in C – standard method
Program 1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int dividend=200,divisor=12;
int quotient,remainder;
quotient=dividend/divisor; // / operator use to compute quotient
remainder=dividend%divisor; // % operator use to compute remainder
printf("Quotient = %d\n",quotient);
printf("Remainder = %d\n",remainder);
getch();
return 0;
}
When the above code is executed, it produces the following result
Quotient = 16 Remainder = 8
In this program,
- integer variables dividend,divisor are declared and initialized
- integer variables quotient,remainder are declared.
- The dividend and divisor both are used to calculate quotient and remainder
- Then,the program is displayed the output of using printf() function
Compute Quotient and Remainder in C – Using user input
Program 2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int dividend,divisor;
int quotient,remainder;
printf("Enter dividend: " );
scanf("%d",÷nd);
printf("Enter divisor: " );
scanf("%d",&divisor);
quotient=dividend/divisor; // / operator use to compute quotient
remainder=dividend%divisor; // % operator use to compute remainder
printf("Quotient = %d\n",quotient);
printf("Remainder = %d\n",remainder);
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter dividend: 200 Enter divisor: 15 Quotient = 13 Remainder = 5
- Integer variables dividend,divisor are declared.
- Integer variables quotient,remainder are declared.
- The program asks input from the user
- Then the user enters the input values for dividend and divisor.
- The program will read the input using scanf() function and store the variables dividend and divisor respectively
- The dividend and divisor both are used to calculate quotient and remainder.
- Then,the program is displayed the output of using printf() function
Compute Quotient and Remainder in C – Using function
Program 3
#include <stdio.h>
#include <stdlib.h>
int findQuitient(int a, int b){
return a/b;
}
int findRemainder(int a, int b){
return a%b;
}
int main()
{
int dividend,divisor;
printf("Enter dividend: " );
scanf("%d",÷nd);
printf("Enter divisor: " );
scanf("%d",&divisor);
printf("Quotient = %d\n",findQuitient(dividend,divisor));
printf("Remainder = %d\n",findRemainder(dividend,divisor));
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter dividend: 230 Enter divisor: 15 Quotient = 15 Remainder = 5
Approach
- Declare dividend and divisor.
- The program takes input from the user
- Then the user enters the input value for dividend and divisor.
- the program will read the input using scanf() function and store the variables in dividend and divisor respectively
- define the function findQuotient() and findRemainder() to find quotient and remainder
- Call the function with argument to produce output
- finally, the program displays the output using printf() function
Program 4
#include <stdio.h>
#include <stdlib.h>
//user define function for find quotient
void findQuotient(int a, int b){
int Quotient= a/b;
printf("Quotient = %d",Quotient);
}
//user define function for find remainder
void findRemainder(int a, int b){
int Remainder =a%b;
printf("\nRemainder %d",Remainder);
}
int main()
{
int dividend,divisor;
//integer variable declaration
printf("Enter dividend: ") ;
//Ask input from the user for dividend
scanf("%d",÷nd);
//Reading the input
printf("Enter divisor: ") ;
//Ask input from the user for divisor
scanf("%d",&divisor);
//Reading the input
findQuotient(dividend,divisor);
//Call the function for display quotient
findRemainder(dividend,divisor);
//Call the function for display remainder
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter dividend: 54 Enter divisor: 6 Quotient = 9 Remainder = 0
Program 5
#include <stdio.h>
#include <stdlib.h>
//user define function for find quotient
void findQuotient(int a, int b){
int Quotient= a/b;
printf("Quotient = %d",Quotient);
}
//user define function for find remainder
void findRemainder(int a, int b){
int Remainder =a%b;
printf("\nRemainder %d",Remainder);
}
int main()
{
int dividend=190,divisor=7;
//integer variable declaration
findQuotient(dividend,divisor);
//Call the function for display quotient
findRemainder(dividend,divisor);
//Call the function for display remainder
getch();
return 0;
}
When the above code is executed, it produces the following result
Quotient = 24 Remainder = 2
Suggested for you
Data type in C language
Variable in C language
Similar post
Python Program to Compute Quotient and Remainder
Java Program to Compute Quotient and Remainder
C++ Program to Compute Quotient and Remainder