Below is the program to find factorial of a number using function in C language. The program has been compiled and executed in Dev C++. The function is a block of code that is specifically designed to do a certain task. Here, the function is taking an argument and calculating the factorial returning its resulting value. Function may or may not return a value explicitly. But it will always return an exit code depending on execution.
CODE:
#include<stdio.h> void main(){ int a,f; int fact(int); printf("Enter a number:"); scanf("%d",&a); f=fact(a); printf("Factorial= %d", f); getch(); } //function fact taking an integer argument to calculate it's factorial. int fact(int x) { int fac=1,i; for(i=x;i>=1;i--){ fac=fac*i; } return fac; // returning the fact value. }
OUTPUT: