1. Function Declaration mein error hay Sahi ye hay (long fact(int);)
2. Function ic tarha call hoga (res=fact(int a);)
3. Logical error factorial nikalne ke lye loop upper se nichay chalti he, jis tarha nichay code mein hay.
Code:
#include <iostream.h>
#include <conio.h>
long fact(int);
void main()
{
clrscr();
int a;
long res;
cout<<"Enter the Integer:? ";
cin>>a;
res=fact(a);
cout<<"The factorial of "<< a <<" is = "<<res;
getch();
}
//Functions Definition
long fact(int a)
{
int counter=1;
for(int i=a;i>0;i--)
counter=counter*i;
return counter;
}
Bookmarks