Factorial of a Number In C Using Function
In this article, we are going to write a program to find Factorial of a Number In C Using Function.
To make this program, we will use the following concept given below.
If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.
Now without wasting time let’s start programming.
Factorial of a Number In C Using Function
Algorithm
- Program Start
- Declaring Variable
- Input Number From the user
- Calling Function
- Loop start
- return result
- function End
- Display Result Through Printf Function
- Program End
Program
//C program to find Factorial of a Number Using Function
#include<stdio.h>
int factorial(int num)
{ int i = 1, fact = 1;
do
{
fact=fact*i;
i++;
} while(i<=num);
return (fact);
}
void main()
{
int n;
printf("Enter a number: ");
scanf("%d",&n);
printf("Factorial of %d is: %d",n,factorial(n));
}
Output
Enter a number: 7
Factorial of 7 is: 5040
Read More
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
Conclusion
So friends, in this article, we have written a program to find Factorial of a Number In C Using Function.
If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.