3 solutions
- 1
Information
- ID
- 652
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- # Submissions
- 25
- Accepted
- 18
- Uploaded By
#include<iostream>
#include<cmath>
using namespace std;
double f(double x,double n)//递归函数
{
if(n<=1)//递归边界
{
return sqrt(1+x);//结束递归
}
else
{
return sqrt(n+f(x,n-1));//递归
}
}
int main()
{
double a,b;
cin>>a>>b;//输入
printf("%.2lf",f(a,b));//保留两位(题目也没说)!!!
return 0;//完结散花
}
#include<bits/stdc++.h>
using namespace std;
double f (double x,double n) {
if (n<=1) {
return sqrt(x+1);
} else {
return sqrt(n+f(x,n-1));
}
}
int main () {
double x,n; cin >> x >> n;
printf("%.2lf",f(x,n));
return 0;
}
By signing up a ZXOJ universal account, you can submit code and join discussions in all online judging services provided by us.