In this tutorial you will learn about the C++ Program to Find Quotient and Remainder and its application with practical example.
C++ Program to Find Quotient and Remainder
In this tutorial, we will learn to create a C++ program that will Find Quotient and Remainder in C++ programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ Programming.
What are Quotient and Remainder?
In the divide operation, the remaining part in the operation is a remainder. The answer part we get after the operation is a quotient.
Algorithm to Find Quotient and Remainder:-
1 2 3 4 5 6 7 |
1. Declaring the variables for the program. 2. Taking the input numbers from the user in number format. 3. Finding the divisor and the divident from the numbers and storing it in a variable. 4. End program. |
Program to Find Quotient and Remainder:-
The integer values are used with operators to perform the arithmetic in programming. The divide operation is done in mathematics to get the remainder and quotient value. First, we will take two numbers and divide them to find the quotient and remainder.
With the help of this program, we can take input and Find Quotient and Remainder.
Program to Find Quotient and Remainder:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <iostream> using namespace std; int main() { //declaring the variables for the program to find the quotient and remainder int divisor, dividend, qtnt, rmdr; //taking input from the user the dividend cout << "Enter dividend: "; cin >> dividend; //taking input from the user the divisor cout << "Enter divisor: "; cin >> divisor; //calculating the quotient for the remainder qtnt = dividend / divisor; rmdr = dividend % divisor; //Printing the remainder and the quotient after the calculations. cout << "Quotient = " << qtnt << endl; cout << "Remainder = " << rmdr; return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- divisor = it will hold the input number value from the user.
- dividend= it will hold the input number value from the user.
- qtnt = it will hold the integer value of the Quotient.
- rmdr = it will hold the integer value of the Remainder.
Taking Input divisor and dividend from the user.
Calculating the quotient and the remainder.
Printing the output.