Programming Reference/Librarys
Question & Answer
Q&A is closed
#include <stdlib.h> div_t div(int numerator, int denominator);
calculates the quotient and remainder from division.
/* * div c example code * http://code-reference.com/c/stdlib.h/div */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ #include <stdlib.h> int main( void ) { int numerator, denominator; printf("please type in numerator and denominator for div\n"); printf("numerator :"); scanf("%d", &numerator); printf("denominator : "); scanf("%d", &denominator); div_t result = div(numerator, denominator); printf("%d = %d*%d + %d\n",numerator , denominator, result.quot, result.rem); return 0; }
Output: user@host:~$ ./div numerator : 2600 denominator : 42 2600 = 42*61 + 38