C++ 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();
}
Back to top button