#include <stdio.h>
int a(int n);
int b(int n);
int c(int n);
int main() {
int n;
int i;
double sum = 0.0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
sum += c(i) ;
}
printf("%.2f", sum);
return 0;
}
int a(int n) {
int answer;
if (n == 1)
answer = 2;
else if (n == 2)
answer = 3;
else
answer = a(n - 1) + a(n - 2);
return answer;
}
int b(int n) {
int answer;
if (n == 1)
answer = 1;
else if (n == 2)
answer = 2;
else
answer = b(n - 1) + b(n - 2);
return answer;
}
int c(int n) {
double answer;
answer = a(n) * 1.0 / b(n);
return answer;
}
以上是我的代码,输入2时,本应输出3.50,但输出结果为3.00,调试也调试过了,找了好久原因都没找到😭
我是初学者,如果大家能帮我看看我一定会非常感谢的!