Krasimir_Slavov

Untitled

Oct 14th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 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 For_Odd_Even_Sum
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. int evenSum = 0;
  15. int oddSum = 0;
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. int number = int.Parse(Console.ReadLine());
  20. if (i % 2 == 0)
  21. {
  22. evenSum += number;
  23. }
  24. else
  25. {
  26. oddSum += number;
  27. }
  28. }
  29. if (evenSum == oddSum)
  30. {
  31. Console.WriteLine($"Yes Sum = {evenSum}");
  32. }
  33. else
  34. {
  35. Console.WriteLine($"No Diff = {Math.Abs(evenSum - oddSum)}");
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment