import java.io.*; /** * 规律:第一项的分母是 1,分子是 2,往后分母是前一项的分子,分子是前一项的分子加上分母。 */ public class Main { public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); public static StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); public static PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws Exception { cin.nextToken(); int n = (int) cin.nval; double sum = 0; double fenzi = 2, fenmu = 1; double a, b; for (int i = 1; i <= n; i++) { sum += fenzi / fenmu; a = fenzi; b = fenmu; fenzi = a + b; fenmu = a; } cout.printf("%.2f", sum); cout.flush(); } }
0.0分
0 人评分
C二级辅导-统计字符 (C语言代码)浏览:782 |
2^k进制数 (C++代码)使用递归方法浏览:736 |
程序员的表白 (C语言代码)浏览:1463 |
简单的a+b (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:545 |
C语言程序设计教程(第三版)课后习题10.1 (Java代码)浏览:1492 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:634 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:742 |
输入输出格式练习 (C语言代码)浏览:773 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:536 |