C Program To Find Factorial of a Number
In this article, we are going to write a c program to find factorial of a number.
We will make this program in the following way -:
- C Program To Find Factorial of a Number Using For Loop
- C Program To Find Factorial of a Number Using While Loop
- C Program To Find Factorial of a Number Using Do While Loop
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.
C Program To Find Factorial of a Number Using For Loop
Algorithm
- Program Start
- Declare Variables
- Input a number from the user
- Assign Value in the variable
- Loop start to find factorial
- Display factorial of a number
- Program End
Program
//C Program To Find Factorial of a Number Using For Loop
#include<stdio.h>
void main()
{
int i,fact=1,n;
printf("Enter a number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
fact=fact*i;
printf("Factorial of %d is: %d",n,fact);
}
Output
Enter a number: 3
Factorial of 3 is: 6
C Program To Find Factorial of a Number Using While Loop
Program
//C Program To Find Factorial of a Number Using While Loop
#include<stdio.h>
void main()
{
int i=1 ,fact=1,n;
printf("Enter a number: ");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("Factorial of %d is: %d",n,fact);
}
Output
Enter a number: 5
Factorial of 5 is: 120
C Program To Find The Factorial of a Number Using Do While Loop
Program
//C Program To Find Factorial of a Number Using Do While Loop
#include<stdio.h>
void main()
{
int i=1 ,fact=1,n;
printf("Enter a number: ");
scanf("%d",&n);
do
{
fact=fact*i;
i++;
} while(i<=n);
printf("Factorial of %d is: %d",n,fact);
}
Output
Enter a number: 10
Factorial of 10 is: 3628800
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 c program to find factorial of a number in this ways -:
- C Program To Find Factorial of a Number Using For Loop
- C Program To Find Factorial of a Number Using While Loop
- C Program To Find Factorial of a Number Using Do While Loop
If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.