#include<stdio.h>
#include<conio.h>
int num(int a)
{
if(a==5)
return 0;
else
return num(a)+num(a+1);
}
int main()
{
printf("%d",num(1));
getch();
return 0;
}
这是我写的5!的程序。我感觉我这个程序,最多能递归5次,不可能溢出的。但是还是溢出了,好奇怪
#include<stdio.h>
#include<conio.h>
int num(int a)
{
if(a==5)
return 0;
else
return num(a)+num(a+1);
}
int main()
{
printf("%d",num(1));
getch();
return 0;
}
这是我写的5!的程序。我感觉我这个程序,最多能递归5次,不可能溢出的。但是还是溢出了,好奇怪
return num(a)+num(a+1);
注意num(a),当a<5的时候,递归调用,num(a),它还是<5。永远不会到达5