C++ Programming

Program to Calculate the Factorial Using For Loop

Write a Program to Calculate the Factorial of Entered no. Using for Loop.  Calculate the Factorial Using For Loop

Algorithm

  • Step 1: Start
    Step 2: Enter a number-a
    Step 3:      for(i=1;i<=n;i++)
  •                {
  •                f=f*i;
  •                }
    Step 4: print Factorial=fact(a)
    Step 5: Stop
  • Source Code
#include<iostream.h>
#include<conio.h>
void main(){
 int n, i, f=1;
 clrscr();
 cout<<"Enter a number: ";
 cin>>n;
               for(i=1;i<=n;i++)
               {
               f=f*i;
               }
 cout<<endl<<"the factorial is: "<<f;
 getch();
}
Back to top button