This blog is under construction

Monday, 30 April 2012

ldiv example in C

Header file:
    stdlib.h

Synopsis:
     ldiv_t div(long numerator, long denominator);

Description:
     It calculates the quotient and remainder of numerator/denominator and its results are stored in the long members quot and rem fields of the structure div_t.


ldiv function C example:


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



  Output:
  jp@jp-VirtualBox:~/cpgms/stdlib$ ./a.out
  Enter the value for numerator and denominator:123123213 43543
  123123213/43543 = 2827
  Remainde:27152


No comments:

Post a Comment