How to display factorial of a number in C++ programming ?
C++ Program to display factorial of a number. |
//Program to display factorial of a number.
#include<iostream.h>
#include<conio.h>
fac(int);
void main()
{
clrscr();
int a;
char z;
do
{
cout<<"Enter a number: ";
cin>>a;
a=fac(a);
cout<<"The factorial is: "<<a<<endl;
cout<<"Do you wish to display another factorial? (y/n): ";
cin>>z;
}
while(z=='y'||z=='Y');
}
fac(int a)
{
int i,b;
for(i=1,b=1;i<=a;i++)
b=b*i;
return b;
}
This C++ Program display factorial of a number.