by Dinesh Thakur Category: C Programming (Pratical)

Consider the program given below, written using the top-down approach, that calculates the factorial of a given integer number using function fact defined in Example. Function fact is called in the main function from a printf function call and the int value returned by it is printed using the %d conversion specification.

Observe that the main function is defined first followed by the function fact, which is called before it is defined. Thus, we need to declare fact in the main function or before it. In the program given above, fact is declared before the main function. The program output is given below.

int fact(int);
void main()
        int n,t;
        printf("Enter any Number : ");
        scanf("%d",& n);
        printf("Factorial of %d is : %d",n,t);
        int fact(int a)
               int p;

Factorial of a Number using Recursion

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.