A Simple Web Classroom
已知第一个人10岁,第二个人比第一个人大2岁,以此类推,用递归算出第八个人几岁?
#include <iostream> using namespace std; int age(int n) { if(n==1) return 10; else return age(n-1)+2; } int main(){ int n; cin >> n; cout << age(n); }