C Program to Compute Quotient and Remainder (2 ways)

By | August 26, 2020

In this article, you will learn to find the quotient and remainder when an integer is divided by another integer.

Examples :

Input: A = 2, B = 7
Output: Quotient = 3, Remainder = 1

Input: A = 27, B = 5
Output: Quotient = 5, Remainder = 2

We can compute quotient and remainder using division and mod operators.

Implementation :

1. Using division and mod operators :

// C Program to Compute Quotient and Remainder
#include <stdio.h>


int main(){
    
   // take dividend
   int num1 = 27;
   // take dividor 
   int num2 = 5;
   
   // to compute quot and reminder
   int quot, rem;

   // compute quotient
   quot = num1 / num2;

   // compute reminder using mod operator
   rem = num1 % num2;

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

   // successful completion
   return 0;
}

Output :

Quotient is: 5
Remainder is: 2  

2. Using function :

// C Program to Compute Quotient and Remainder
#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() {

   // take dividend
   int num1 = 27;
   // take dividor 
   int num2 = 5;
   
   // to compute quot and reminder
   int quot, rem;
    
    //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);
    
    // successful completion
    return 0;
}

Output :

Quotient is: 5
Remainder is: 2  



Please write comments if you find anything incorrect. A gentle request to share this topic on your social media profile.