pointeur de fonction

#include <stdio.h> //Compiler version gcc 6.3.0 /*On declare 4 fonctions*/ int ad (int num1, int num2); int sub (int num1, int num2); int mul (int num1, int num2); int div (int num1, int num2); int main() { int chif, num1, num2; int(*op[4])(num1, num2); op[0]=ad; op[1]=sub; op[2]=mul; op[3]=div; printf("Choisissez deux nombres separes par enter\n"); scanf("%d%d", &num1, &num2); printf("choisissez un chiffre entre 0 et 3 pour +-*/ \n"); scanf("%d", &chif); printf("le reultat est %d\n", op[chif](num1, num2)); return 0; } int ad (int x, int y) { return (x+y); } int sub (int x, int y) { return(x-y); } int mul (int x, int y) { return(x*y); } int div (int x, int y) { return(x/y); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.