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
4
Answer:
initialize fact;
and in long factorial write
return fact
Explanation:
Answered by
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
Science,
6 months ago
Social Sciences,
6 months ago
Biology,
6 months ago
Social Sciences,
1 year ago
Biology,
1 year ago
English,
1 year ago
English,
1 year ago
Math,
1 year ago