Arithmetic Caculation

C++ Program to Compute Quotient and Remainder

C++ Program to Compute Quotient and Remainder

In this tutorial, we will discuss the C++ Program to Compute Quotient and Remainder

In this post, we are going to learn how to find quotient and remainder using two numbers via different 3 ways in C++language

Program to Compute Quotient and Remainder

Compute Quotient and Remainder – standard method

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int dividend=400,divisor=30;
    int quotient,remainder;

    quotient=dividend/divisor;// /operator use to compute quotient
    remainder=dividend%divisor;// %operator use to compute remainder
    cout<<"Quotient = "<<quotient;
    cout<<"\nRemainder = "<<remainder;
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Quotient = 13
Remainder = 10

 

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 cout<<

 

Compute Quotient and Remainder – Using user input

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int dividend,divisor;
    int quotient,remainder;
    cout<<"Enter dividend: " ;
    cin>>dividend;
    cout<<"Enter divisor: " ;
    cin>>divisor;
    quotient=dividend/divisor;  // / operator use to compute quotient
    remainder=dividend%divisor;  // % operator use to compute quotient
    cout<<"Quotient = "<<quotient;
    cout<<"\nRemainder = "<<remainder;
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter dividend: 245
Enter divisor: 8
Quotient = 30
Remainder = 5

Approach

  • integer variables dividend and divisor are declared,
  • integer variables quotient and 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 cin>> 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 cout<<

Compute Quotient and Remainder – Using function

Program 3

#include <iostream>
#include <conio.h>
using namespace std;
//user define function for find quotient
 void findQuotient(int a, int b){
   int Quotient= a/b;
   cout<<"Quotient =" <<Quotient;
    }
    //user define function for find remainder
    void findRemainder(int a, int b){
   int Remainder =a%b;
    cout<<"\nRemainder "<<Remainder;
    }
int main()
{
    int dividend=100,divisor=5;
    //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 = 20

Remainder = 0

 

Program 4

#include <iostream>
#include <conio.h>
using namespace std;

 int findQuitient(int a, int b){
   return a/b;
    }
    int findRemainder(int a, int b){
   return a%b;
    }
int main()
{
    int dividend,divisor;
    cout<<"Enter dividend: " ;
    cin>>dividend;
    cout<<"Enter divisor: " ;
    cin>>divisor;

    cout<<"Quotient = "<<findQuitient(dividend,divisor);
    cout<<"\nRemainder "<<findRemainder(dividend,divisor);
    getch();
    return 0;
}

When the above code is executed, it produces the following result

Enter dividend: 500
Enter divisor: 55
Quotient = 9
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 cin>> and store the variables in dividend and divisor respectively
  • define the function findQuotient() and findRemainder() to find quotient and remainder
  • Call the function to produce output
  • finally, the program displays the output using cout<< function

 

 

Program 5

#include <iostream>
#include <conio.h>
using namespace std;
//user define function for find quotient
 void findQuotient(int a, int b){
   int Quotient= a/b;
   cout<<"Quotient =" <<Quotient;
    }
    //user define function for find remainder
    void findRemainder(int a, int b){
   int Remainder =a%b;
    cout<<"\nRemainder "<<Remainder;
    }
int main()
{
    int dividend,divisor;
    //integer variable declaration
    cout<<"Enter dividend: " ;
    //Ask input from the user for dividend
    cin>>dividend;
    //Reading the input
    cout<<"Enter divisor: " ;
    //Ask input from the user for divisor
    cin>>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: 240
Enter divisor: 25
Quotient = 9
Remainder = 15

 

 

 

Suggested for you

Data type in C++ language

Variable in C++ language

Operator in C++ language

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

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.