2 Star 8 Fork 3

Cyouagain / C语言经典编程详解

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
【C语言经典编程】习题2-5 求平方根序列前N项和 (15分).md 1.31 KB
Copy Edit Raw Blame History

快速找到所需题目:浙大版c语言程序设计第三版题目集一览表

微信搜索公众号【IT学长】:

习题2-5 求平方根序列前N项和

本题要求编写程序,计算平方根序列$\sqrt{1}$+$\sqrt{2}$+$\sqrt{3}$+⋯的前N项之和。可包含头文件math.h,并调用sqrt函数求平方根。

输入格式:

输入在一行中给出一个正整数N。

输出格式:

在一行中按照“sum = S”的格式输出部分和的值S,精确到小数点后两位。题目保证计算结果不超过双精度范围。

输入样例:

10

输出样例:

sum = 22.47

代码:

#include<stdio.h>
#include<math.h>
int main()
{
    int n;
    scanf("%d",&n);
    int i;
    //if(n!=0){
    double sum=0.0;
    for(i=1;i<=n;i++)
    {
        sum+=sqrt((double)i);
    }
    printf("sum = %.2lf\n",sum);
    //}
    return 0;
}
C
1
https://gitee.com/cyouagain/C_pta.git
git@gitee.com:cyouagain/C_pta.git
cyouagain
C_pta
C语言经典编程详解
master

Search