This blog is under construction

Monday 30 April 2012

div example in C

Header file:
    stdlib.h

Synopsis:
     div_t div(int numerator, int denominator);

Description:
     It computes the quotient and remainder of numerator/denominator and stores them correspondingly in the quot and rem fields of the structure div_t.


div function C example:


  #include<stdio.h>
  #include<stdlib.h>
  int main() {
        int num, denom;
        div_t res;
        printf("Enter the value for numerator and denominator:");
        scanf("%d%d", &num, &denom);
        res = div(num, denom);
        printf("%d/%d = %d\nRemainde:%d\n", 
                   num, denom, res.quot, res.rem);
        return 0;
  }




  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the value for numerator and denominator:100 23
  100/23 = 4
  Remainder:8



No comments:

Post a Comment