This shows you the differences between two versions of the page.
— |
c:stdlib.h:div [2024/02/16 01:04] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== div ====== | ||
+ | <code c> | ||
+ | #include <stdlib.h> | ||
+ | div_t div(int numerator, int denominator); | ||
+ | </code> | ||
+ | calculates the quotient and remainder from division. | ||
+ | |||
+ | ===== div C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * 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; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== Output ==== | ||
+ | |||
+ | Output: | ||
+ | user@host:~$ ./div | ||
+ | numerator : 2600 | ||
+ | denominator : 42 | ||
+ | 2600 = 42*61 + 38 | ||
+ | |||
+ | |||