program in c calculate the factorial of a given number using pointer to function.
#include<stdio.h> #include<conio.h> void (*FunPtr)(int ); void Fact(int n) { int f=1,i; for(i=1;i<=n;i++) { f=f*i; } printf("Factorial =%d",f); } int main() { int a; printf("Enter a number:-"); scanf("%d",&a); FunPtr = &Fact; FunPtr(a); getch(); return 0; }
Output:-
0 Comments