Home » Program to find the Quotient and Remainder

# Program to find the Quotient and Remainder

## Write a program to find the quotient and remainder

In this article, we will discuss the program to find the quotient and remainder in different programming languages such as in C, Java, PHP, and python. But before writing the programs, let’s first see a brief description of the quotient and remainder.

## What is the quotient?

The different parts of division are Dividend, Divisor, Quotient, and Remainder. Quotient can be defined as the resultant of the division. The formula for quotient is –

In division, a number is divided by another number to get the output in the form of another number. The dividend is the number that is getting divided, and the divisor is the number that divides the given number.

In a fraction, the numerator is dividend, denominator is divisor, and when numerator is divided by the denominator, the result will be quotient. For instance, suppose we have to divide 20 (dividend) by 4 (divisor); we will get 5, which is the quotient.

## What is the remainder?

Remainder is defined as a value that is left after division. As an instance, if we divide 25 with 4, we will get 1 as a remainder. If the number divides another number completely, the remainder will be 0.

Remainder is always smaller than the divisor; if it is larger, that means the division is not completed. But remainder can be less or greater than the quotient; for instance, if we divide 41 by 7, we will get 5 as a quotient, and 6 as a remainder which is less than divisor but greater than the quotient.

We know the method of division –

So, the formula for remainder will be –

Now, let’s see the programs of finding quotient and remainder in different programming languages.

### Programs to find the quotient and remainder

Program: Write a program to find the quotient and remainder in the C language.

Output Program: Write a program to find the quotient and remainder in the C# language.

In C#, we can use the Math.DivRem method to find the quotient and remainder of two numbers. We can also write the program without using Math.DivRem method. So, let’s see both approaches of finding quotient and remainder in C#.

Using Math.DivRem() method

Output: Native approach

Output: Program: Write a program to find the quotient and remainder in Java language.

Output: Program: Write a program to find the quotient and remainder in JavaScript language.

In this example, we are using the Math.floor() function to calculate the divisor. The JavaScript Math.floor() method decreases the given number up to the closest integer value and returns it. For example, 3 for 3.7, 5 for 5.9, etc.

If the given number is already an integer, the floor() method returns it directly.

Output: Program: Write a program to find the quotient and remainder in PHP language.

In PHP, we can find the quotient and remainder by using the intdiv() and fmod() functions.

The intdiv() is a mathematical function of PHP, which is used to calculate integer division. It returns the integer quotient of the division.

PHP fmod() function is used to return the floating point remainder of the division of the argument.

Now, let’s see the programs with or without using the default PHP functions.

Using intdiv() and fmod() functions

Output: Native approach

Output: Program: Write a program to find the quotient and remainder in Python language.

Here, we also see two approaches of finding quotient and remainder in python. The first approach is by using the divmod() function and second by native approach.

Python divmod() function is used to get the remainder and quotient of two numbers. This function takes two numeric arguments and returns a tuple.

Using divmod() function

Output: Using native approach

Output: So, that’s all about the article. We have discussed the program to find the quotient and remainder in C, Java, C#, PHP, python, and JavaScript. Hope you find the article informative and gain knowledge about the finding of quotient and remainder in different programming languages.

Next TopicPrograms List