Commit 00b91fe9 by Andrew Dahl

Solved Problem 6

parent aabc0eca
Showing with 33 additions and 0 deletions
Question:
The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 55^2 = 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.
Answer: 25164150
#include <iostream>
using namespace std;
int main() {
int sum_of_squares = 0;
int sum_of_numbers = 0;
int low = 1;
int high = 100;
for(int i = low; i <= high; i++)
{
sum_of_squares += i*i;
sum_of_numbers += i;
}
cout << (sum_of_numbers * sum_of_numbers) - sum_of_squares << endl;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment