In this tutorial, we will discuss the concept of Find quotient and remainder using function in C++ 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 using function in C++ programming language
To find the quotient, we have used the division(/) operator. we have divided (dividend by divisor) two numbers one by another
To find remainder, we have use modular(%) operator . The dividend is divided by the divisor and the remainder is returned by the modular(%) operator
Program 1
In this program, the user initialize two integer numbers using two variables as quotient and remainder and then the program calculates the quotient and remainder of the given numbers using function in C++ language
#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=1500,divisor=60; //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: 25 Remainder: 0
The program allows to enter two integer and then the program calculates the quotient and remainder of the given numbers using function in C++ language
Program 2
#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: 440 Enter divisor: 25 Quotient: 17 Remainder: 15
The program allows to enter two integer and then the program calculates the quotient and remainder of the given numbers using function in C++ programming language with return
Program 3
#include <iostream> #include <conio.h> using namespace std; //user define function for find quotient int findQuotient(int a, int b){ return a/b;//The output return to the main method } //user define function for find remainder int findRemainder(int a, int b){ return a%b;//The output return to the main method } 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 cout<<"Quotient =" <<findQuotient(dividend,divisor); //Call the function for display quotient cout<<"\nRemainder "<<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: 1245 Enter divisor: 40 Quotient: 31 Remainder: 5
Suggested for you
Data types in C++ language
Types of function 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 calculate quotient and remainder
C code to calculate quotient and remainder
C++ code to calculate quotient and remainder
Python code to calculate quotient and remainder
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…