1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 15:48:42 +00:00
202401-programming-assignments/【额外练习】循环结构/7-1 循环-Fibonacci数列的运算.c

21 lines
273 B
C

#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
double a = 2, b = 1, sum = 0;
for (int i = 1; i <= n; i++) {
sum += a / b;
double temp = a;
a = a + b;
b = temp;
}
printf("%.6lf\n", sum);
return 0;
}