42-Write a program to find the factorial of a number using function

Program: 42

Write a program to find the factorial of a number using function.

#include
#include
int factorial(int);
void main()
{
    int num, fact;
    printf("Enter any number: ");
    scanf("%d", &num);
    fact=factorial(num);
    printf("The factorial of %d is %d.", num, fact);
getch();
}
int factorial(int x)
{
    int i, f=1;
    for(i=x;i>=1;i--)
    {
        f=f*i;
    }
    return (f);
}
Output
Enter any number: 6 The factorial of 6 is 720.
Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.