Arithmetic Caculation

Program to Compute Quotient and Remainder in C

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",&dividend);
    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",&dividend);
    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",&dividend);
    //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

Operator in C anguage

While loop 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

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.