编程介的小学生 2019-09-28 21:58 采纳率: 20.5%
浏览 210

Calculate the formula 公式计算

Problem Description
You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2.

Input
In each case, there is an odd positive integer n.

Output
Print the sum. Make sure the sum will not exceed 2^31-1

Sample Input
3

Sample Output
10

  • 写回答

1条回答 默认 最新

  • 那雨中的田野 2019-09-28 23:33
    关注
    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int i,n;
        int sum;
        printf("Please input num n:\n");
        scanf("%d",&n);
        for(i = 1;i <= n;i+=2)
        {
            sum += pow(i,2);
        }
        if(sum<pow(2,31))
            printf("sum=",sum);
        else
            printf("The sum is too big!");
        return 0;
    }   
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题