Program in C to passing function as an argument
#include<stdio.h> #include<conio.h> int Fun(int x(int,int),int i,int j) { return x(i,j); } //Addition int add(int a,int b) { return (a+b); } //Multiplication int mul(int a,int b) { return (a*b); } int main() { int m,a,b; printf("Enter two number:-"); scanf("%d%d",&a,&b); m=Fun(mul,a,b); printf("Multiplication = %d ",m); m=Fun(add,a,b); printf("\nAddition = %d ",m); }
Output:-
0 Comments