# 求一个范围内的所有整数的平方和

#include <stdio.h>
// validate that input is an integer
int get_int(void);
// validate that range limits are valid
bool bad_limits(int begin, int end, int low, int high);
// calculate the sum of the squares of the integers
// a through b
double sum_squares(int a, int b);
int main(void)
{
const int MIN = -1000;  // lower limit to range
const int MAX = +1000;  // upper limit to range
int start;              // start of range
int stop;               // end of range

printf("This program computes the sum of the squares of "
"integers in a range.\nThe lower bound should not "
"be less than -1000 and\nthe upper bound should not "
"be more than +1000.\nEnter the limits (enter 0 for "
"both limits to quit):\nlower limit: ");
start = get_int();
printf("upper limit: ");
stop = get_int();
while (start !=0 || stop != 0)
{
else
{
printf("The sum of the squares of the integers ");
printf("from %d to %d is %g\n", start, stop, answer);
}
printf("Enter the limits (enter 0 for both "
"limits to quit):\n");
printf("lower limit: ");
start = get_int();
printf("upper limit: ");
stop = get_int();
}
printf("Done.\n");

return 0;
}

int get_int(void)
{
int input;
char ch;

while (scanf("%d", &input) != 1)
{
while ((ch = getchar()) != '\n')
putchar(ch);  // dispose of bad input
printf(" is not an integer.\nPlease enter an ");
printf("integer value, such as 25, -178, or 3: ");
}

return input;
}

double sum_squares(int a, int b)
{
double total = 0;
int i;

for (i = a; i <= b; i++)
total += i * i;

}

bool bad_limits(int begin, int end, int low, int high)
{
bool not_good = false;

if (begin > end)
{
printf("%d isn't smaller than %d.\n", begin, end);
not_good = true;
}
if (begin < low || end < low)
{
printf("Values must be %d or greater.\n", low);
not_good = true;
}
if (begin > high || end > high)
{
printf("Values must be %d or less.\n", high);
not_good = true;
}

return not_good;
}


#### 求小于等于n的所有与7无关的正整数的平方和。

2017-11-09 11:49:36

#### 定义一个方法求两个整数范围内所有数的累加和

2018-04-21 18:48:17

#### 给定一段连续的整数，求出他们中所有偶数的平方和以及所有奇数的立方和。

2016-01-10 10:30:27

#### 求某个正整数范围内的所有素数

2016-09-19 23:22:45

#### 求各位数字的平方和

2014-03-19 19:53:54

#### 1到10之间所有数的平方和立方

2017-11-19 21:04:09

#### Java 求整数各位数平方之和

2017-06-27 13:03:16

#### ﻿﻿﻿﻿求连续数中偶数的平方和，奇数的立方和

2015-07-20 16:05:36

#### zzuli OJ 1049: 平方和与立方和

2015-08-28 16:19:31

#### 计算并输出1到n之间的所有数的平方和立方。

2017-11-09 21:09:35