转载于开摆C的博客
一、题目描述计算的和(N为输入数)。
输入格式:一个整数N。
输出格式:输出计算结果(保留6位小数)。
输入输出样例输入:
2
输出:
二、代码实现1.500000
#include#include //保留小数要用的头文件 using namespace std; int main() { int n; double sum=0; cin>>n; //循环相加,注意分子要写为1.0 for(int i=1;i<=n;i++) { sum=sum+1.0/i; } //保留6位小数,并输出结果 cout< 三、运行结果 2 1.500000 -------------------------------- Process exited after 2.066 seconds with return value 0 请按任意键继续. . .



