
C program to find factorial of a number
Algorithm
Input: Input a number
output: Find and displays factorial of a number
- Start
- Input a numbers say n to find factorial
- sum = 1
- for (int i = 1; i<= n; i++)
4.1 sum = sum * i - print sum
- stop
C Program
#include <stdio.h>
int main( )
{
int n,sum = 1;
printf("Enter a number to find the factorial: ");
scanf("%d", &n);
for(int i = 1; i <= n ; i++) {
sum = sum * i;
}
printf("The factorial of %d is %d", n , sum);
}
Note: This Program was created using visual studio code. The Program file can be downloaded by clicking here
FlowChart

Note: This Flowchart was created using a program called Raptor. The flowchart file can be downloaded by clicking here
Input
n:5
Output
The factorial of 5 is 120
Note: Please read the explanation of how I implemented the Fibonacci series in 'C program to display fibonacci series' to understand the logic of factorial too. The explanation of Fibonacci can be viewed by clicking here.
Comments