计算给定整数的平方和

#include stdio.hint main(void){int sum, count, max_count;sum = 0;count = 1;printf(How many squares would you like to sum? );

编程学习网为您整理以下代码实例,主要实现:计算给定整数的平方和,希望可以帮到各位朋友。

#include <stdio.h>

int main(voID){
  int sum, count, max_count;
  sum = 0;
  count = 1;

  printf("How many squares would you like to sum? ");
  scanf("%d", &max_count);

  while (count <= max_count){
    sum = sum + count * count;
    count++;
  }
  printf("The sum of the first %d squares is: %d\n", max_count, sum);

  return 0;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐