Table of Contents
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 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,
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
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
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
Similar post
Python Program to Compute Quotient and Remainder
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.