Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 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. namespace lab_2._1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //case1
  14. int n, sum1, sum = 0;
  15. Console.WriteLine("Input n");
  16. n = Convert.ToInt32(Console.ReadLine());
  17. for(int i = 1; i<=n; i++ )
  18. {
  19. sum += (int)Math.Pow(i, 2);
  20. //Console.WriteLine(sum); uncomment to check iterations
  21. }
  22. //case2
  23. sum1 = (n * (n + 1) * (2 * n + 1)) / 6;
  24.  
  25. if(sum==sum1)
  26. {
  27. Console.WriteLine("Formule is right");
  28. }
  29. else
  30. {
  31. Console.WriteLine("Formule isn't right");
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement