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();
}

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.