#include<stdio.h> void fun(int x) { if(x/2>0)fun(x/2); printf("%d",x); } main() { fun(3);
#include<stdio.h> void fun(int x) { if(x/2>0)fun(x/2); printf("%d",x); } main() { fun(3);
日期:2012-02-16 15:34:51 人气:1
实际上这个程序可以改成:
#include
void fun(int x)
{
if(x>2)
fun(x/2);
printf("%d",x);
}
main()
{
fun(3);
printf("\n");
}
fun 的作用是:如果输入的参数大于2,就用参数x/2递归调用自己。实际上,绝大部分递归调用都可以写成循环。
这个递归函数就可以写成
void fun(int x)
{
if(x