📄 ep3_15.cpp
字号:
//3.15 下面递归函数执行结果是什么?
#include<iostream>
using namespace std;
void p1(int w){
int i;
if(w>0){
for(i=0;i<w;i++) cout<<'\t'<<w;
cout<<endl;
p1(w-1);
}
}
void p2(int w){
int i;
if(w>0){
p2(w-1);
for(i=0;i<w;i++) cout<<'\t'<<w;
cout<<endl;
p2(w-1);
}
}
void p3(int w){
int i;
if(w>0){
for(i=0;i<w;i++) cout<<'\t'<<w;
cout<<endl;
p3(w-1);
p3(w-2);
}
}
void p4(int w){
int i;
if(w>0){
for(i=0;i<w;i++) cout<<'\t'<<w;
cout<<endl;
p4(w-1);
for(i=0;i<w;i++) cout<<'\t'<<w;
cout<<endl;
}
}
int main(){
p1(4);cout<<endl;
p2(4);cout<<endl;
p3(4);cout<<endl;
p4(4);cout<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -