Table of Contents

## Introduction

This program deals with the computation of Quotient and Remainder.

It is very important to understand the division between two values. When both are of the same data type, and both are of different data types.

The values of the Dividend and Divisor are taken from the user, and then Quotient and Remainder are calculated. Dividend and Divisor will be of integer type only.

To understand this program, you should know about the following:

1. Data types in C

2. Variables, literals, and constants

3. Operators in C

## Program

#include<iostream> using namespace std; int main() { int D, d, R, Q; cout<<"Enter the value of Dividend: "; cin>>D; cout<<"Enter the value of Divisor: "; cin>>d; Q=D/d; // calculating quotient R=D%d; // calculating remainder cout<<"Quotient: "<<Q<<endl; cout<<"Remainder: "<<R<<endl; return 0; }

## Output

## Explanation

Four variables are declared of ‘int’ data type as per the requirement of the program.

The user is then asked to enter the Dividend value and the divisor value that get stored at the address of variables ‘D’ and ‘d’, respectively.

**Q=D/d; **here we did the division part with the use of ‘/’ operator and calculated the quotient when ‘D’ is divided by ‘d’. Since both are of ‘int’ data type and we already know the quotient of two int values yields an int value as resultant. Thus, the final value is stored in the ‘Q’ variable of type ‘int’.

**R=D%d; **‘%’ modulo operator is used to calculate the remainder. Obviously, the remainder will be an integer value, that’s why assigned to a variable ‘R’ of ‘int’ data type.

Both values are printed on the screen, as shown in the output.

Note: Division operator ‘**/**’ computes the quotient either between float or integer variables but modulus operator ‘**%**’ gives the remainder value when one integer is divided by another. It doesn’t work with floating variables.

## Leave a Reply