document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*The sum of the squares of the first ten natural numbers is,
  2.  
  3. 1^2 + 2^2 + ... + 10^2 = 385
  4. The square of the sum of the first ten natural numbers is,
  5.  
  6. (1 + 2 + ... + 10)^2 = 55^2 = 3025
  7. Hence the difference between the
  8. sum of the squares of the first ten natural numbers and
  9. the square of the sum is
  10. 3025 - 385 = 2640.
  11.  
  12. Find the difference between the sum of the squares of the first one hundred(100) natural numbers
  13. and the square of the sum.
  14.  
  15. 0. int n=100, i, sumOfSq=0, sqOfSum, sum=0, difference;
  16. 1. for(i=1,i<=n,i++) {sumOfSq+=pow(i,2);}
  17. 2. for(i=1,i<=n,i++) {sum+=i} sqOfSum= pow(sum,2);
  18. 3. difference = sqOfSum-sumofSq;
  19.  
  20. Start 9:48am -> end 10:18am
  21. Sat 4/12/2010
  22. Note: it still have my debug part
  23. */
  24. #include <iostream>
  25. #include <math.h>
  26. #include <iomanip>
  27. using namespace std;
  28. const int n = 100;
  29.  
  30. int main()
  31. {
  32.     int i;
  33.     double sumOfSq=0.0, sum=0.0, sqOfSum, difference;
  34.     cout << setiosflags(ios::fixed);
  35.     cout << "When n = "<< n << endl;
  36.    
  37.     cout << "Sum of Square of the first "<< n<<" natural numbers[sumOfSq] =";
  38.     for (i=1; i<=n; i++)
  39.     {
  40.         cout << i << "^2";
  41.         sumOfSq += pow(i,2);
  42.         if (i!=n) {cout << "+";}
  43.     }
  44.     cout << " = " << sumOfSq << endl;
  45.    
  46.     cout << "Sum of the first " <<n<<" natural numbers[sum] =";
  47.     for (i=1; i<=n; i++)
  48.     {
  49.         cout << i;
  50.         sum += i;
  51.         if (i!=n) {cout << "+";}
  52.     }
  53.     cout << " = " << sum << endl;
  54.     cout << "Square of the Sum of the first " << n << " natural numbers[sqOfSum] =";
  55.     sqOfSum = pow(sum,2);
  56.     cout << sqOfSum << endl;
  57.     difference = sqOfSum-sumOfSq;
  58.     cout << "Difference between sqOfSum and sumOfSq  = "
  59.          <<  sqOfSum << " - " << sumOfSq << " = "
  60.          << difference << endl;
  61.     cin.get();
  62.     return 0;
  63. }
');