Codeforcoding

C++ Program to compute Quotient and Remainder

C++ Program to compute Quotient and Remainder of two numbers

In this tutorial, we will discuss the concept of C++ Program to compute Quotient and Remainder of two numbers when the one number divided by another

In this topic, we are going to learn how to calculate quotient and remainder of two numbers (one number divided by another)in C++ programming language

C++ Program to compute Quotient and Remainder of two numbers
Quotient and Remainder of two numbers

What is quotient and remainder

To find the quotient, we have used the division(/) operator. we have divided (dividend by divisor) two numbers

To find remainder, we have use modular(%) operator . The dividend is divide by the divisor and the remainder is returned by the modular(%) operator

 

C++ program to find quotient and remainder

Program to find quotient and remainder

Program 1

In this program, the user initialize two integer numbers using two variables as dividend and divisor and then the program calculates the quotient and remainder of the given two numbers using division and modular operators

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

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

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

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

Quotient: 30
Remainder: 0

 

Program to find quotient and remainder-Entered by user

Program 2

the program allows to enter two integer and then the program calculates the quotient and remainder of the given two numbers using division and modular operators

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

int main()
{
    int dividend,divisor,quotient,remainder;
    //Declare integer variables
    cout<<"Enter dividend: " ;
    //Ask input from the user for dividend
    cin>>dividend;
    //Reading the input from the user
    cout<<"Enter divisor: " ;
    //Ask input from the user for divisor
    cin>>divisor;
     //Reading the input from the user
    quotient=dividend/divisor;
    //Calculate quotient
    remainder=dividend%divisor;
    //Calculate remainder
    cout<<"Quotient = "<<quotient;
    //Display quotient
    cout<<"\nRemainder = "<<remainder;
    //Display remainder
    getch();
    return 0;
}

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

Enter dividend: 1000
Enter divisor: 60
Quotient: 16
Remainder: 40

 

Suggested for you

Operator in C++ language

Data types in C++ language

Variable in C++ language

Function in C++ language

Types of function in C++ language

Recursion in C++ language

Pointer in C++ language

 

Similar post

C Program to Divide of two integer numbers

Java Program to Divide of two integer numbers

C++ Program to Divide of two integer numbers

Python Program to Divide of two integer numbers

 

C Program to Divide of two integer numbers using function

Java Program to Divide of two integer numbers using method

C++ Program to Divide of two integer numbers using function

Python Program to Divide of two integer numbers using function

 

Java code to find quotient and remainder

C code to find quotient and remainder

C++ code to find quotient and remainder

Python code to find quotient and remainder

C Program to compute Quotient and Remainder of two numbers
Python Program to compute Quotient and Remainder
Exit mobile version