C语言求1到50的数的三次方的和。

C语言求1到50的数的三次方的和。

代码部分:

#include <stdio.h>
#include <math.h>       //引用math.h头文件
void main()
{
    int k;
    double s;
    for(s=0,k=1;k<=50;k++)  //循环到50
    {
        s=s+pow(k,3);       //用pow函数计算3次方
    }
    printf("%.0f\n",s);     //输出结果
}

猜你喜欢

转载自blog.csdn.net/Deng7326/article/details/115983495