div C Library Function

The function div divides numerator by denominator and returns the integral quotient and remainder of the division. It returns a structure of type div_t, which has two members: quot(quotient) and rem(remainder).

Function prototype of div

div_t div(int numerator, int denominator);
  • numerator : This is the numerator of a fraction.
  • denominator : This is the denominator of a fraction.

Return value of div

This function returns the quotient and remainder of numerator/denominator as a div_t type(defined in stdlib library) which has two members quot(quotient) and rem(remainder).

C program using div function

The following program shows the use of div function to find quotient and remainder of integer division.

div C Library Function

#include <stdio.h>
#include <stdlib.h>
 
int main(){
    int numerator, denominator;
    div_t response;
    printf("Enter numerator and denominator\n");
    scanf("%d %d", &numerator, &denominator);
     
    response = div(numerator, denominator);
    printf("Remainder of %d/%d is %d\n", 
        numerator, denominator, response.rem);
    printf("Quotient of %d/%d is %d\n", 
        numerator, denominator, response.quot);
     
    return 0;
}

Output

Enter numerator and denominator
25 3
Remainder of 25/3 is 1
Quotient of 25/3 is 8