您的位置:首页 > 编程语言 > Go语言

函数的递归

2014-06-11 07:07 281 查看
函数的递归和循环:
#include <stdio.h>
int main(void)
{
char i,s;

for(i = 1,s = 1;i <=4;i++)
{
s *= i;
}
printf("%d\n",s);

return 0;
}
/* 用递归来实现一把 */
#include <stdio.h>

long test(int);

int main(void)
{

}

long test(int n)
{
long f;
//   printf("%d\n",n);
if(n > 1)
{
f = test(n - 1)*n;
//       printf("%d\n",n);
}
else
{
//       printf("%d\n",n);
f = 1;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  It's always a go