Hi,I am a new C++ learner.The follow prgram produces a wrong
result,but I can't find the wrong.Can you help me?Thank you!
#include<stdio. h>
long factorial( long number);
int main()
{
int a;
for ( a = 0;a<10;a++ ){
printf("%2d! = %1d\n",a,factor ial( a ));
}
return 0;
}
long factorial( long number )
{
if ( number <=1 ){
return 1;
}
else{
return ( number * factorial(numbe r - 1));
}
the result as follows
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! =5040
8! = -25216
9! = -30336
Atentions,pleas e.The result 8! and 9! are wrong.But Why?
result,but I can't find the wrong.Can you help me?Thank you!
#include<stdio. h>
long factorial( long number);
int main()
{
int a;
for ( a = 0;a<10;a++ ){
printf("%2d! = %1d\n",a,factor ial( a ));
}
return 0;
}
long factorial( long number )
{
if ( number <=1 ){
return 1;
}
else{
return ( number * factorial(numbe r - 1));
}
the result as follows
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! =5040
8! = -25216
9! = -30336
Atentions,pleas e.The result 8! and 9! are wrong.But Why?
Comment