CPP04 – (a) Write a CPP program to print the factorial of a given number.

By | October 16, 2018

(a) Write a CPP program to print the factorial of a given number.

CODE:-

#include<iostream.h>
#include<conio.h>
void main()
{
int i,num;
long fact=1;
clrscr();
cout<<“Enter Number : “;
cin>>num;
for(i=num;i>0;i–)
{
fact=fact*i;
}
cout<<“Factorial = “<<fact<<endl;
getch();
}

#include<iostream.h>
#include<conio.h>
void main()
{
  int i,num;
  long fact=1;
  clrscr();
  cout<<"Enter Number : ";
  cin>>num;
  for(i=num;i>0;i--)
  {
   fact=fact*i;
  }
  cout<<"Factorial = "<<fact<<endl;
  getch();
}

SCREEN SHOTS:-

CPP_program_Factorial

OUTPUT:-

CPP_program_Factorial_Out