Look at this program compiled using Turbo c++ 3.0 compiler
Aim is to calculate the factorial of a no.
#include<iostream.h>
#include<conio.h>
long double factorial(int);
void main() //main function
{
int inp;
clrscr();
cout<<"Enter a positive no. ";
cin>>inp;
cout<<"factorial is :"<<factorial(inp);//displays factorial
getch();
}
long double factorial(int a)
{
long double fact=1;
while(!a==0)
{
fact=a*fact;
--a;
}
return fact;
}
But when it runs it gives unexpected result, it can't find the factorial of no. grater than six.
Can you correct this program and explain why it is wrong without altering it's simplicity.....
Remember this program is from a beginner level program so, only correct it , don't use complex methods.