单选题 适中
#23016

要求以下程序的功能是计算:s = 1 + 1/2 + 1/3 + ... + 1/10。 #include <iostream> using namespace…

要求以下程序的功能是计算:s = 1 + 1/2 + 1/3 + ... + 1/10。

#include <iostream>

using namespace std;

int main() {

int n;

float s;

s = 1.0;

for (n = 10; n > 1; n--)

s = s + 1 / n;

cout << s << endl;

return 0;

}

程序运行后输出结果错误,导致错误结果的程序行是( )。

未登录也能判分,登录后才会记录
答案与解析
正确答案:C
这道题暂未补解析。