1 /*
2. Question: How old are five people sitting together? He said he is two years older than 4th. Asked 4th people about the age, he said
Three or three people are two years old. Ask the third person, and say that the person is two years older than 2nd. Ask 2nd people, saying they are two years older than the first. Last
4. Ask the first person, he says he is 10 years old. How old is the fifth person?
5
6. Program Analysis: Using recursive methods, recursion is divided into two stages: push-back and recursion. To know the age of the fifth person, you need to know
7. The age of the fourth person, and so on, is pushed to the first person (10 years old) and then back.
8 */
9 # include <stdio. h>
10
11 int age (int n)
12 {
13 int c;
14
15 if (n = 1)
16 return 10;
17
18 else
19 {
20 c = age (n-1) + 2;
21 return c;
22}
23}
24
25 int main ()
26 {
27 // int I;
28
29 printf ("his age is: % d \ n", age (5 ));
30
31 // for (I = 1; I <6; I ++)
32 // printf ("the % d man is: % d \ n", I, age (I ));
33
34 return 0;
35}
From zhengmian