Created
May 29, 2014 17:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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