编程介的小学生 2019-08-05 21:58 采纳率: 20.5%
浏览 469

怎么来实现一个公式的计算,用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条回答 默认 最新

  • Rotch 2019-08-05 23:19
    关注

    为了C币。。。
    long 一个 sum = 0;
    这个还是for循环
    for (int i = 0; i <= n; i += 2)
    每次sum += i * i;

    最后 printf

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退