Description
按如下递归公式求函数值。
x=1时 f(x)=10;x>1时 f(x)=f(x-1)+2
Input
整型变量x
Output
f(x)
Sample Input
10
Sample Output
28
#include<iostream>
using namespace std;
int f(int x)
{
return x == 1 ? 10 : f(x - 1) + 2;
}
int main()
{
int x,s;
cin>>x;
s=f(x);
cout<<s<<endl;
}