Computer Science, asked by divyashreer1999, 1 year ago

The following code finds out the factorial of a number. There is some error in it. Can you fix the bug?


#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;
}

Answers

Answered by mohammads
4

Answer:

initialize fact;

and in long factorial write

return fact

Explanation:

Answered by Prajwal1244
2

Answer:

#include <iostream>

long factorial (long);

int main ()

{

long number;

std::cin>>number;

std::cout<< factorial (number);

return 0;

}

long factorial (long a)

{int fact=1;

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

fact=fact*i;

return(fact);

}

Explanation:

This is answer.

Similar questions