mituri

[C++] roznica sumy kwadratow i kwadratu sumy

Oct 1st, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. /*
  2. Project Euler("https://projecteuler.net/archives")
  3. Problem 6
  4.  
  5. The sum of the squares of the first ten natural numbers is,
  6. 1^2 + 2^2 + ... + 10^2 = 385
  7. The square of the sum of the first ten natural numbers is,
  8. (1 + 2 + ... + 10)^2 = 55^2 = 3025
  9. 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.
  10.  
  11. Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
  12. */
  13.  
  14. int main(){
  15.  
  16. int sumSquares = 0, sumNumbers = 0;
  17. for(int i = 1; i <= 100; i++){
  18. sumSquares += i*i;
  19. sumNumbers += i;
  20. }
  21. cout << (sumNumbers * sumNumbers) << " - " << sumSquares << " = " <<(sumNumbers * sumNumbers) - sumSquares << endl;
  22.  
  23. system("PAUSE");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment