题解 | #规律数列求和#

规律数列求和

https://www.nowcoder.com/practice/e05d1c142b3d4898be7183289a00ce5f

#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    unsigned long sum = 0;
    long temp=0;
    for(int i=1;i<=10;i++)
    {

        temp=9*pow(10,i-1)+temp;
        //cout<<temp<<endl;
        sum=sum+temp;
    }
    cout<<sum<<endl;
    return 0;
}

这题要注意变量的数据类型选择。

全部评论

相关推荐

昨天 13:49
深圳大学 运营
点赞 评论 收藏
分享
昨天 12:14
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务