ksmk99

Sum square difference №6

Sep 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. //The sum of the squares of the first ten natural numbers is,
  8.  
  9. //12 + 22 + ... + 102 = 385
  10. //The square of the sum of the first ten natural numbers is,
  11.  
  12. //(1 + 2 + ... + 10)2 = 552 = 3025
  13. //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.
  14.  
  15. //Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
  16.  
  17. namespace 6
  18. {
  19.     class Program
  20.     {
  21.         static void Main(string[] args)
  22.         {
  23.             long sum = 0;
  24.             for (int i = 1; i < 101; i++) sum += i * i;
  25.             Console.WriteLine(- sum + 101 * 101 * 2500);
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment