#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[len];
for (i = 1;i < len - 2;i++)
ruler[i]= ' ';
ruler[len - 1]= '\0';
int max = len - 2;
int min = 0;
ruler[min] = ruler[max] = '!';
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[j] = ' ';
}
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[mid] = '!';
subdivide(ar,low,mid,level-1);//第一次进行递归--左边
subdivide(ar,mid,high,level - 1);//第二次进行递归--右边
}