Computer Science, asked by Vivekvijay026, 8 months ago

#include
int main ()
{
long number;
std::cin>>number;
std::cout<< factorial (number);
return 0;
}
long factorial (long a);
{
for(int i=1;i<=a;i++)
fact=fact*i;
}
find the error and correct it

Answers

Answered by sswaraj04
0

Answer:

There are two errors

(1) fact is not declared in factorial function and just used directly

(2) fact variable is not return back so that output is shown

so final program should be :-

#include

int main ()

{

long number;

std::cin>>number;

std::cout<< factorial (number);

return 0;

}

long factorial (long a);

{

long fact = 1;

for(int i=1;i<=a;i++)

fact=fact*i;

return fact;

}

Explanation:

Hope it helps :-)

Similar questions