C++旅程第五站------函数你我他222
本帖最后由 这是她 于 2020-4-29 20:49 编辑What lies behind you and what lies in front of you,pales in comparison to what lies inside of you.
{:10_272:} 递归递归..............
#include <iostream>
using namespace std;
void cultured(int n);
void subdivide(char ar[],int low,int high,int level);
int main()
{
int smart;
cout << "Enter a number of smart : " << endl;
cin >> smart;
cultured(smart);//调用函数
int len = 128,divs = 7,i;
char ruler;
for (i = 1;i < len - 2;i++)
ruler= ' ';
ruler= '\0';
int max = len - 2;
int min = 0;
ruler = ruler = '!';
cout << ruler << endl;
for (i = 1;i <= divs;i++)
{
subdivide(ruler,min,max,i);
cout << ruler << endl;
for(int j = 1;j < len - 2;j++)
ruler = ' ';
}
return 0;
}
//包含一个递归调用的递归
void cultured(int n)
{
cout << "Cultured........." << n << " (smart at " << &n << ")" << endl;
if (n > 0)
cultured(n-1);//调用n-1,一直往下调用。直到n=0;调用完以后在返回回来;
cout << n << " : earnest!\n";
}
//包含多个递归调用的递归
void subdivide(char ar[],int low,int high,int level)
{
if(level == 0)
return;
int mid = (high + low) / 2;
ar = '!';
subdivide(ar,low,mid,level-1);//第一次进行递归--左边
subdivide(ar,mid,high,level - 1);//第二次进行递归--右边
}
渣渣一枚{:10_329:}大佬们!你给建议 给你fafa {:10_287:} 不给建议?{:10_254:}你还是给个吧{:10_264:}
页:
[1]