Skip to content

Instantly share code, notes, and snippets.

@NerdyNerves
Created May 29, 2014 17:49
Show Gist options
  • Save NerdyNerves/9d1a7806d8cfb4592fef to your computer and use it in GitHub Desktop.
Save NerdyNerves/9d1a7806d8cfb4592fef to your computer and use it in GitHub Desktop.
Finds the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
#include <iostream>
using namespace std;
int main() {
int x, // Holds sum of the squares
y, // Holds square of the sum
z, // Holds difference of sum of the squares
i, // used for loop
n; // used for loop
const int MAX = 100; // Holds maximum
for (i=1; i<=MAX;i++) {
x+=(i*i);
}
for (n=1; n<=MAX;n++) {
y+=n;
}
y = (y*y);
z = y - x;
cout << y << endl;
cout << x << endl;
cout << z << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment