The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
前十个自然数的平方和是,
1 2 + 2 2 + ... + 10 2 = 385
前十个自然数之和的平方是,
(1 + 2 + ... + 10)2 = 55 2 = 3025
因此,前十个自然数的平方和与总和的平方之差为3025-385 = 2640。
找出前100个自然数的平方和与总和的平方之间的差
思路:
这道题很简单啦
#include <stdio.h>
int main(){
int sum1 = 0, sum2 = 0;
for(int i = 1; i <= 100; ++i){
sum1 += i;
sum2 += i * i;
}
printf("%d\n", sum1 * sum1 - sum2);
return 0;
}