C program to find factorial of a given number using function

C program to find factorial of a given number using function

This C program is to find factorial of a given number using function.For example, factorial of a given number(5) using function  will be factorial(5) = 120.

Dry run of the program has been given here(click on the link) only additional part is the use of function.

If you yet need the dry run of the program or any other query, then kindly leave a comment in the comment box or mail me, I would be more than happy to help you.

Program

#include <stdio.h>

int fact(int);

void main()
{
	int no,factorial;
 
  	printf("Enter a number to calculate it's factorial\n");
  	scanf("%d",&no);
  	factorial=fact(no);
    printf("Factorial of the num(%d) = %d\n",no,factorial);
//printf("Factorial of the num(%d) = %d\n",no,fact(no));//another way of calling a function//comment above two lines if you want to use this
}

int fact(int n)
{
    int i,f=1;
    for(i=1;i<=n;i++)
    {
        f=f*i;
    }
    return f;
}

Output

Share Me!