C Program to Compute Quotient and Remainder

devquora
devquora

Posted On: Dec 15, 2020

C Program to Compute Quotient and Remainder

 

Overview:

In this article, you will learn to find the quotient and remainder when an integer is divided by another Integer. First of all let's understand about Number, Integer, Division, Dividend, Divisor, Quotient and Remainder. Moreover, I will Demonstrate to Compute Quotient and Remainder. After all, I will write the logic and C Program to Compute Quotient and Remainder with output.

Table of contents:

  1. What is Number?
  2. What is Integer?
  3. What do you know about Division?
  4. The Quick rules about Division
  5. What is Dividend?
  6. What is Divisor?
  7. What is Quotient?
  8. What is Remainder?
  9. Demonstration to Compute Quotient and Remainder
  10. Logic to Compute Quotient and Remainder
  11. C Program to Compute Quotient and Remainder
  12. Conclusion

What is Number?

An arithmetical value, expressed by a word, symbol, or figure, representing a particular quantity and used in counting and making calculations.

What is Integer?

Integer is a number that can be written without a fractional component.

Integers are generally denoted as Z and can be represented as follows:

Z= {……-8,-7,-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,……}

What do you know about Division?

Division is one of the four basic operations of arithmetic. The usual written symbol for division is (÷). In spreadsheets and other computer applications the ‘/’ (forward slash) symbol is used. Division is the opposite of multiplication in mathematics. The ten divided by two is written as 10 ÷ 2. This is the same as ‘sharing’ 10 sweets between 2 children. Both children must end up with the same number of sweets. In this example the answer is 5.

Therefore, 10 ÷ 2 = 5

10 is considered as the dividend, 2 is divisor and 5 is quotient as well as remainder is 0.

In division we will see the relationship between the dividend, divisor, quotient and remainder.

The Quick rules about Division

  • When you divide 0 by another number the answer is always 0.
  • For example: 0 ÷ 2 = 0. That is 0 sweets shared equally among 2 children, each child gets 0 sweets.
  • When you divide a number by 0 you are not dividing at all (this is quite a problem in mathematics). 2 ÷ 0 is not possible.
  • You have 2 sweets but no children to divide them among. You cannot divide by 0.
  • When you divide by 1, the answer is the same as the number you were dividing. 2 ÷ 1 = 2.
  • Two sweets divided by one child.
  • When you divide by 2 you are halving the number. 2 ÷ 2 = 1.
  • Any number divided by the same number is 1. 20 ÷ 20 = 1.
  • Twenty sweets divided by twenty children - each child gets one sweet.
  • Numbers must be divided in the correct order. 10 ÷ 2 = 5 whereas 2 ÷ 10 = 0.2.
  • Ten sweets divided by two children is very different to 2 sweets divided by 10 children.
  • All fractions such as ½, ¼ and ¾ are division sums. ½ is 1 ÷ 2. One sweet divided by two children. 

What is Dividend?

In division, The number which we divide is called the < strong > dividend. </strong >

What is Divisor?

In division, The number by which we divide is called the divisor.

What is Quotient?

In division, The result obtained is called the quotient.

What is Remainder?

In division, The number left over is called the remainder.

    Demonstration to Compute Quotient and Remainder

    In division, we will see the relationship between the dividend, divisor, quotient, and remainder. The number which we divide is called the dividend. The number by which we divide is called the divisor. The result obtained is called the quotient. The number left over is called the remainder.

      For instance, In this example 55 ÷ 9 = 6 and 1
      Dividend = 55
      Divisor = 9
      Quotient = 6
      Remainder = 1
      The relationship between these four are as follows:
      Dividend = Quotient * Divisor + Remainder
      Therefore, We can say that, 55 = 6 * 9 + 1

    Logic to Compute Quotient and Remainder

        • Step 1: Take two integers (dividend and divisor) which are stored in variable dividend and divisor respectively.
        • Step 2: Then the quotient is evaluated using division/operator and stored in the variable quotient.
        • Step 4: Similarly, the remainder is evaluated using modulus % operator and stored in remainder variable.
        • Step 5:Finally, the quotient and remainder are displayed using printf() function.

    C Program to Compute Quotient and Remainder

    #include <stdio.h>
    
    int main()
    {
    	int dividend, divisor;
    	int quotient, remainder;
    	
    	printf("Enter dividend = ");
    	scanf("%d",&dividend);
    
    	printf("Enter divisor = ");
    	scanf("%d",&divisor);
    	/* The "/" Arithmetic operator returns the quotient
        * Here the num1 is divided by num2 and the quotient
        * is assigned to the variable quot
        */
            // Computes quotient 
    	quotient= dividend/divisor;
    	/* The modulus operator "%" returns the remainder after
        * dividing num1 by num2.
        */
            // Computes remainder
    	remainder= dividend%divisor;
    	
    	printf("quotient = %d, remainder = %d\n",quotient,remainder);
    	
    	return 0;
    }
    

    The output of the Program with code:

    When the above code is executed, It produces the following results:

    Enter dividend: 25

    Enter divisor: 4

    Quotient = 6

    Remainder = 1

     

    Division Output

    Explanation:

    In the above Program,  variables Dividend and Divisor are divided using the arithmetic operator / to get the quotient as result stored in the variable quotient; and using the arithmetic operator % to get the remainder as result stored in the variable remainder.

    Conclusion:

    This program evaluates and Compute Quotient and Remainder when an integer is divided by another integer. In this program, the user is asked to enter two integers (dividend and divisor) which are stored in variable dividend and divisor respectively. Finally, the quotient and remainder are displayed as output.

      Please Login or Register to leave a response.

      Related Articles

      C Program Examples

      C Program to convert Decimal to Binary Number

      A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

      C Program Examples

      C program to reverse a string

      This program reversed the entered string that means opposite of the previous string sequence...

      C Program Examples

      C program to reverse an Integer number

      Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..