BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Find Quotient and Remainder

Last Updated: September 24, 2017 by Chaitanya Singh | Filed Under: C Programs

Program to find quotient and remainder based on the dividend & divisor values entered by user.

Example 1: Program to find Quotient and Remainder

In this program, user is asked to enter the dividend and divisor and the program then finds the quotient and remainder based on the input values.

#include <stdio.h>
int main(){
   int num1, num2, quot, rem;

   printf("Enter dividend: ");
   scanf("%d", &num1);

   printf("Enter divisor: ");
   scanf("%d", &num2);

   /* The "/" Arithmetic operator returns the quotient
    * Here the num1 is divided by num2 and the quotient
    * is assigned to the variable quot
    */
   quot = num1 / num2;

   /* The modulus operator "%" returns the remainder after
    * dividing num1 by num2.
    */
   rem = num1 % num2;

   printf("Quotient is: %d\n", quot);
   printf("Remainder is: %d", rem);

   return 0;
}

Output:

Enter dividend: 15
Enter divisor: 2
Quotient is: 7
Remainder is: 1

Example 2: Program to find Quotient and Remainder using function

In this program, we are doing the same thing that we have done in the above program, but here we are using functions in order to find the quotient and remainder. We have created two user defined functions for the calculation. To understand this program, you should have the basic understanding of following C programming topics:

  1. Functions in C
  2. Function call by value in C
#include <stdio.h>
// Function to computer quotient
int quotient(int a, int b){
   return a / b;
}

// Function to computer remainder
int remainder(int a, int b){
   return a % b;
}

int main(){
    int num1, num2, quot, rem;
    printf("Enter dividend: ");    
    scanf("%d", &num1);
    printf("Enter divisor: ");    
    scanf("%d", &num2);
    
    //Calling function quotient()    
    quot = quotient(num1, num2);

    //Calling function remainder()    
    rem = remainder(num1, num2);
    printf("Quotient is: %d\n", quot);    
    printf("Remainder is: %d", rem);
    return 0;
}

Check out the related C programs:

  1. C program to Add two numbers
  2. C program to multiply two floating point numbers
  3. C program to find ASCII value of a character
  4. C program to calculate and print the value of nCr

Top Related Articles:

  1. C Program to calculate Area of an Equilateral triangle
  2. C Program to find the Size of int, float, double and char
  3. C Program to Generate Multiplication Table
  4. Hello World Program in C
  5. C Program to Find GCD of two Numbers

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap