3 solutions

  • 4
    @ 2024-1-23 11:09:05
    #include<bits/stdc++.h>
    using namespace std;
    double x,n;
    double f(double x,double n){
    	if(n==1) return sqrt(1+x);
    	return sqrt(n+f(x,n-1));
    }
    int main(){
    	cin>>x>>n;
    	cout<<fixed<<setprecision(2)<<f(x,n)<<endl; 
    	return 0;
    }
    

    高情商:递归 低情商:TLE

    • 4
      @ 2024-1-20 18:13:36
      #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;//完结散花
      }
      
      • 1
        @ 2024-2-19 11:42:57
        #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;
        }
        
        • 1

        Information

        ID
        652
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        3
        Tags
        # Submissions
        25
        Accepted
        18
        Uploaded By