SDUT-1199 C語言實驗(JAVA*)

C語言實驗——計算表達式

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

計算下列表達式值: 

 

Input

輸入x和n的值,其中x爲非負實數,n爲正整數。

Output

輸出f(x,n),保留2位小數。

Sample Input

3 2

Sample Output

2.00

Hint

Source

//package leslie;

import java.util.*;

public class Main {
	
	public static double F(int x,int n)
	{
		double ans=Math.sqrt(1+x);
		for(int i=2;i<=n;i++)
			ans=Math.sqrt(ans+i);
		return ans;
	}
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int x=cin.nextInt();
		int n=cin.nextInt();
		System.out.printf("%.2f\n",F(x,n));
	}
}

發佈了194 篇原創文章 · 獲贊 48 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章