IvetValcheva

02. Equal Sums Even Odd Position

Dec 4th, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp17
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int first = int.Parse(Console.ReadLine());
  10. int second = int.Parse(Console.ReadLine());
  11.  
  12. int oddSum;
  13. int evenSum;
  14.  
  15. string currentNum;
  16.  
  17. for (int num = first; num <= second; num++)
  18. {
  19. oddSum = 0;
  20. evenSum = 0;
  21.  
  22. currentNum = num.ToString();
  23.  
  24. for (int i = 0; i < currentNum.Length; i++)
  25. {
  26. if (i % 2 == 0)
  27. {
  28. evenSum += currentNum[i];
  29. }
  30. else
  31. {
  32. oddSum += currentNum[i];
  33. }
  34. }
  35.  
  36. if (oddSum == evenSum)
  37. {
  38. Console.Write(num + " ");
  39. }
  40. }
  41. }
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment