C/div: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Linia 53:
* reszta, czyli result.rem odpowiada n % d
* (n/d)*d + n%d powinno być równe n.
 
 
<source lang=c>
 
 
/*
gcc d.c -Wall
./a.out
 
http://www.gnu.org/software/libc/manual/html_node/Integer-Division.html
*/
#include <stdio.h> // printf
#include <stdlib.h> // lldiv_t
 
int main(){
 
long long int n = 20;
long long int d = 6;
 
lldiv_t result; //
result = lldiv (n, d);
// Now result.quot is 3 and result.rem is 2.
printf(" %lld / %lld = %lld * %lld + %lld \n", n, d, result.quot, d, result.rem);
 
return 0;
}
</source>
 
Wynik :
 
20 / 6 = 3 * 6 + 2
 
 
[[en:C_Programming/C_Reference/stdlib.h/div]]