编程介的小学生 2019-05-15 17:13 采纳率: 20.5%
浏览 1125

1^2+3^2+5^2+……+ n ^2.公式的计算的问题怎么采用C语言程序代码编写的过程技术的实现的方式

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条回答 默认 最新

  • 逝_doom 2019-05-15 20:01
    关注
    long calc(int n){
        int i = 1;
        long result = 0 ;
        for(int i = 1;i<n;i = i+2){
            result += i*i;
        }
        return result;
    } 
    
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容