Programmation Avancée en C


opere.c

00001 #include <stdio.h>
00002 
00003 int somme(int a, int b) { return a+b; }
00004 int diff (int a, int b) { return a-b; }
00005 int mult (int a, int b) { return a*b; }
00006 int mod  (int a, int b) { return a%b; }
00007 
00008 int opere(int a, int b, int (*f)(int, int) ) {
00009     return (*f)(a,b);
00010 }
00011 
00012 int main() 
00013 {
00014     int a = 14, b = 5;
00015     printf("a + b = %d\n",  opere(a,b,somme) );
00016     printf("a - b = %d\n",  opere(a,b,diff)  );
00017     printf("a * b = %d\n",  opere(a,b,mult)  );
00018     printf("a %% b = %d\n", opere(a,b,mod)   );
00019     return 0;
00020 }