C Program to Find Factorial of a Given Number Using User Defined Function
Question: Write a program in C to read a number from a user and then find factorial of that number using user defined function.
Program
#include<stdio.h>
#include<conio.h>
/* Function Prototype */
long int fact(int n);
/* Main function */
int main()
{
long int number, result;
/* Input */
printf("Enter any positive integer: ");
scanf("%ld", &number);
/* Function call */
result = fact(number);
printf("%ld != %ld",number,result);
return(0);
}
long int fact(int n)
{
long int i, f=1;
for(i=1;i<= n;i++)
{
f = f*i;
}
return f;
}
Output of above program :
Enter any positive integer: 12 12 != 479001600 Note: ↲ indicates enter is pressed.