1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <stdio.h>
int add(int x, int y)
{
return x+y;
}
int sub(int x, int y)
{
return x-y;
}
int mult(int x, int y)
{
return x*y;
}
int main()
{
typedef struct {
char *libelle;
char operator;
int (*fct)(int , int);
} t_operation;
t_operation tabOP[]={
{"addition", '+', add},
{"soustraction", '-', sub},
{"multiplication", '*', mult},
{NULL, 0, NULL},
};
t_operation *pt_op;
int x=10, y=12;
for (pt_op=tabOP; pt_op->fct != NULL; pt_op++)
printf("%d %c %d = %d\n", x, pt_op->operator, y, (*pt_op->fct)(x, y));
} |
Partager