c/c++课的作业合集,都是很简单的文件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

21 lines
452 B

#include <stdio.h>
int main() {
int n = 0;
scanf("%d", &n);
double numerator = 2.0, //和分母
denominator = 1.0; //分子
double oldNumerator = 0.0;
double result = 0.0;
for (int i = 0; i < n; ++i) {
result += numerator / denominator;
oldNumerator = numerator;
numerator += denominator;
denominator = oldNumerator;
}
printf("%.6f", result);
}