Header Ads Widget

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 number\n");
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



Post a Comment

0 Comments