Programmation Avancée en C


fonctions_arith.c

00001 #include <stdio.h>
00002 
00003 int add    (int x, int y) { return x + y; }
00004 int minus  (int x, int y) { return x - y; }
00005 int mult   (int x, int y) { return x * y; }
00006 int int_div(int x, int y) { return x / y; }
00007 int modulo (int x, int y) { return x % y; }
00008 
00009 int main()
00010 {
00011     int x, y;
00012     printf("x = ");  scanf("%d", &x);
00013     printf("y = ");  scanf("%d", &y);
00014     printf("x + y = %d\n", add(x,y)     );
00015     printf("x - y = %d\n", minus(x,y)   );
00016     printf("x * y = %d\n", mult(x,y)    );
00017     if (y != 0) { /* on ne peut pas diviser par 0 */
00018             printf("x / y = %d\n", int_div(x,y) );
00019             printf("x %% y = %d\n", modulo(x,y) );
00020     }
00021     return 0;
00022 }