[ create a new paste ] login | about

Link: http://codepad.org/BlwTf5f8    [ raw code | output | fork ]

C++, pasted on Jan 18:
#include <iostream>
// Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
// Sum of squares = 338351
using namespace std;

int main()
{
    long int a = 0;
    long int b = 0;
    for(int i=0; i<=100; i++)
    {
        a += i*i;
    }
    cout << "Sum of Squares is: " << a << endl;
    for (int x=1; x<=100; x++)
    {
        b += x;
    }
    b *= b;

    cout << "Square of sum is: " << b << endl;

    int c = 0;
    c = (b - a);

    cout << "Difference between square of sum, and sum of squares is: " << endl << "*" << c <<
 "*" << endl;

 return 0;
}


Output:
1
2
3
4
Sum of Squares is: 338350
Square of sum is: 25502500
Difference between square of sum, and sum of squares is: 
*25164150*


Create a new paste based on this one


Comments: