#include <stdio.h>
#include<iostream>
using namespace std;
void g(int a,int b)
{
if(a<b){
g(a,b-1);
}
cout<<"递归函数"<<endl;//这里不能加else语句 ,否则只能输出1,
//因为递归到1的时候符合条件,其他的都不符合
cout<<b<<endl;//如果没有else,则每个人只负责打印一个,其他的都交给别人做
}
void f(int a,int b)
{
int i ;
for(i=a;i<=b;i++)
{
cout<<"循环函数"<<endl;
cout<<i<<endl;
}
}
int main(){
f(1,10);//循环
g(1,10); //递归
return 0;
}
递归算法:打印1-10
猜你喜欢
转载自blog.csdn.net/cheng_hai_yan/article/details/88756175
今日推荐
周排行