Programming Reference/Librarys
Question & Answer
Q&A is closed
#include <stdlib.h> ldiv_t ldiv(long int numerator, long int denominator);
calculate the quotient and remainder in integer division (long integer).
/* * ldiv c example code * http://code-reference.com/c/stdlib.h/ldiv */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ #include <stdlib.h> int main( void ) { long int numerator, denominator; printf("please type in (long int) numerator and denominator for ldiv\n"); printf("(long int) numerator :"); scanf("%li", &numerator); printf("(long int) denominator : "); scanf("%li", &denominator); ldiv_t result = ldiv(numerator, denominator); printf("%li = %li*%li + %li\n",numerator , denominator, result.quot, result.rem); return 0; }
Output: user@host:~$ ./ldiv please type in (long int) numerator and denominator for ldiv (long int) numerator :1234567890 (long int) denominator : 1234 1234567890 = 1234*1000460 + 250