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

21 lines
273 B
C
Raw Permalink Normal View History

2024-11-18 15:10:07 +00:00
#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;
}