C++ 不允许对函数进行嵌套定义 但是可以进行嵌套调用
#include<iostream>
using namespace std;/* 递归调用
第一个人年龄age1 年龄十岁
第二个人年龄age2 比第一个人大2岁
第三个人年龄age3 比第二个人大2岁
第四个人年龄age4 比第三个人大3
第五个人年龄age5 比第四个人大2岁
求第五个人年龄
*/
int age_2();
int age_3();
int age_4();
int age_5();
int age_5(){
int age5;
return age5=age_4()+2;
}
int age_4(){
int age4;
return age4=age_3()+3;
}
int age_3(){
int age3;
return age3=age_2()+2;
}
int age_2(){
int age2 ;
return age2=age_1()+2;
}
int age_1(){
int age1;
return age1=10;
}
int main(){
int age1,age2,age3,age4,age5;
age1=age_1() ;
age2=age_2() ;
age3=age_3() ;
age4=age_4() ;
age5=age_5() ;
cout<<"age1="<<age1<<endl;
cout<<"age2="<<age2<<endl;
cout<<"age3="<<age3<<endl;
cout<<"age4="<<age4<<endl;
cout<<"age5="<<age5<<endl;
}