C语言:运用递归算年龄
/**********************************************************************************@fuction:算同学的年龄
@time :2021/5/18
@author :LaoGu
***********************************************************************************/
#include<stdio.h>
int main()
{
int age(int n);
int n,i ;
for(i=0;i<5;i++)
{
printf("输入是哪一个同学(1-5):");
scanf("%d",&n);
printf("NO.5,age:%d\n",age(n));
}
return 0;
}
int age(int n)
{
int c;
if(n == 1)
c = 10;
else
c = age(n-1)+2;
return (c);
}
页:
[1]