Write a program to calculate the factorial for given number using function

 Code:-


#include<stdio.h>
// function for calculationg factorial
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return f;
}

// Driver function
int main()
{
int n;
printf(“Enter a numbern”);
scanf(“%d”,&n);
printf(“Factorial of the number is: %d”,fact(n));
return 0;
}

Output:-

Enter a number
5
Factorial of the number is: 120



Leave a Reply

Your email address will not be published.