文章
23
粉丝
234
获赞
47
访问
177.1k
#include<stdio.h> int main() { int N; scanf("%d", &N); int i; float sum = 0; float fenzi = 2.0; float fenmu = 1.0; for(i = 0; i < N; i++) { sum = sum + fenzi/fenmu; float tmp = fenzi + fenmu; fenmu = fenzi; fenzi = tmp; } printf("%.2f", sum); }
fenmu = fenzi;
fenzi = fenzi + fenmu;//此时的fenmu已经变成之前的fenzi了
要警惕这种错误
登录后发布评论
fenmu = fenzi;
fenzi = fenzi + fenmu;//此时的fenmu已经变成之前的fenzi了
要警惕这种错误