Programming

Program to Calculate the Factorial Using While

Write a Program to Calculate the Factorial of Entered No. Using While

Algorithm

  • Start
  • Enter a number-a
  • e(n!=0)
    {
    f=f*n;
    n–;
    }
  • Print Factorial=fact(a)
  • Stop

Source Code

#include<iostream.h>
#include<conio.h>
void main(){
 int n, i, f=1;
 clrscr();
 cout<<"Enter a number: ";
 cin>>n;
          while(n!=0)
          {
             f=f*n;
             n--;
           }
 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.