**Factorial Program in C, C++ (C Plus Plus, CPP) with flow chart**

In this tutorial, we will learn about the followings;

- Flowchart of the factorial program
- C++ program for factorial program
- C program for factorial program

**Logic of factorial**

Suppose we want to calculate the factorial of 4, then we need to perform the multiplication in such a way as given below;

4*3*2*1=24, so factorial of 4 is 24.

Similarly, suppose we want to calculate the factorial of 5, then we need to perform the multiplication in such a way as given below;

5*4*3*2*1=120, so factorial of 5 is 120.

**Flowchart of the factorial program**

**C++ program for factorial program**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<iostream> #include<conio.h> using namespace std; int main() { int i; int num; unsigned long long fact=1; cout<<"Please enter a number: "; cin>>num; for(i=1;i<=num;i++) { fact=fact*i; } cout<<"Factorial of entered number is: "<<fact; getch(); } |

**Output**

## SFT (Shamil’s Flow Table )

Are you interested to Read about SFT(Shamil’s Flow Table)?

Let us see the factorial program with Shamil’s program flow table.

**C program for factorial program**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdio.h> #include<conio.h> int main() { int i; int num; unsigned long long fact = 1; printf("Please Enter a number: "); scanf("%d",&num); for(i=1; i<=num;i++) { fact *= i; } printf("Factorial of Entered number is %llu", fact); getche(); } |

**Output**

**Example of for loop to display the number as 5, 10, 15, 20, ……40, 45**

1 2 3 4 5 6 7 8 9 10 11 12 13 | #include<iostream> #include<conio.h> using namespace std; int main() { int i; for(i=0;i<45;) { i=i+5; cout<<i; ; } } |

Latest posts by Prof. Fazal Rehman Shamil (see all)

- List of Public service commissions - August 31, 2020
- Comparison of fee structure of Pakistani Universities - June 1, 2020
- Past Guess Paper of Auditing - May 12, 2020