Table of Contents
This program uses a division operator on two input numbers. The output is a quotient and a remainder is printed to the console.
Problem Definition
When the program runs, it ask for two input numbers, a and b. The number a is dividend and b is divisor for the program which uses division operator (/) to divide the numbers and return the results.
The program performs the simple division as follows,
\begin{aligned}
&q = a/b\\ \\
&r = a % b
\end{aligned}Where a and b are two integer values and q is quotient and r is remainder values respectively.
Flowchart – Program to find Quotient and Remainder

Program Codes – Remainder and Quotient
C
C++
Java
Python
#include <stdio.h>
#include <conio.h>
main()
{
int dnd, div, quotient, remainder;
int i;
//Enter Input Numbers 'a' and 'b'
printf ("Enter the dividend:");
scanf ("%d", &dnd);
printf ("Enter the divisor :");
scanf ("%d",&div);
//Compute Quotient and Remainder
quotient = dnd/div;
remainder = dnd % div;
//Print the Results
for(i=0;i < 20;i++)
printf("_");printf("\n\n");
printf ("Quotient = %d\n", quotient);
printf ("Remainder= %d\n", remainder);
for(i=0;i<20;i++)
printf("_");printf("\n");
getch ();
return 0;
}#include <iostream>
using namespace std;
int main() {
int dnd, div, quotient, remainder;
int i;
// Enter Input Numbers
cout << "Enter the dividend:";
cin >> dnd;
cout << "Enter the divisor :";
cin >> div;
// Compute Quotient and Remainder
quotient = dnd / div;
remainder = dnd % div;
// Print the Results
for (i = 0; i < 20; i++)
cout << "_";
cout << "\n\n";
cout << "Quotient = " << quotient << endl;
cout << "Remainder= " << remainder << endl;
for (i = 0; i < 20; i++)
cout << "_";
cout << endl;
return 0;
}import java.util.Scanner;
public class QuotientRemainder {
public static void main(String[] args) {
int dnd, div, quotient, remainder;
int i;
Scanner sc = new Scanner(System.in);
// Enter Input Numbers
System.out.print("Enter the dividend:");
dnd = sc.nextInt();
System.out.print("Enter the divisor :");
div = sc.nextInt();
// Compute Quotient and Remainder
quotient = dnd / div;
remainder = dnd % div;
// Print the Results
for (i = 0; i < 20; i++)
System.out.print("_");
System.out.print("\n\n");
System.out.println("Quotient = " + quotient);
System.out.println("Remainder= " + remainder);
for (i = 0; i < 20; i++)
System.out.print("_");
System.out.println();
sc.close();
}
}# Program to find quotient and remainder
# Enter Input Numbers
dnd = int(input("Enter the dividend:"))
div = int(input("Enter the divisor :"))
# Compute Quotient and Remainder
quotient = dnd // div
remainder = dnd % div
# Print the Results
for i in range(20):
print("_", end="")
print("\n")
print("Quotient =", quotient)
print("Remainder=", remainder)
for i in range(20):
print("_", end="")
print()
The most important code in the above program is as follows.
\begin{aligned}&
quotient = dnd/div \\ \\
&remainder = dnd \hspace{1mm} \% \hspace{1mm}div;
\end{aligned}The values of quotient and remainder is printed to console before the program terminates.
Output
In the results below, 34 is divided by 6 and results in quotient = 5 and remainder = 4 because
\begin{aligned}&
a = q * b + r \\ \\
&34 = 5 * 6 + 4\\ \\
&= 30 + 4
\end{aligned} Enter the dividend:34
Enter the divisor :6
_____________________
Quotient = 5
Remainder= 4
_____________________