Write a program to calculate the factorial of a number using function

#include<stdio.h>
#include<math.h>
int main()
{
    printf("Enter a Number to Find Factorial: ");
    printf("\nFactorial of a Given Number is: %d ",fact());
    return 0;
}
int fact()
{
    int i,fact=1,n;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        fact=fact*i;
    }
    return fact;
}

OUTPUT:
Enter a Number to Find Factorial: 7

Factorial of a Given Number is: 5040

0 Comments:

Post a Comment