Advertisement
Alexander_B

Odd Even Sum

Feb 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 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 DomashnoEvenOrOdd
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. int eventSum = 0;
  16.  
  17. int oddtSum = 0;
  18.  
  19. for (int i = 0; i < n; i++)
  20. {
  21. int input = int.Parse(Console.ReadLine());
  22.  
  23. if (i % 2 == 1)
  24. {
  25. eventSum += input;
  26. }
  27. else
  28. {
  29. oddtSum += input;
  30. }
  31.  
  32. }
  33.  
  34. if (eventSum == oddtSum)
  35. {
  36.  
  37. Console.WriteLine($"Yes");
  38. Console.WriteLine($"Sum = {eventSum}");
  39. }
  40. else
  41. {
  42. int difference = eventSum - oddtSum;
  43.  
  44. Console.WriteLine($"No");
  45. Console.WriteLine($"Diff = {Math.Abs(difference)}");
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement