Advertisement
bullit3189

Even sums on left and right positions

Nov 1st, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using System;
  2.  
  3. public class Program
  4. {
  5. public static void Main()
  6. {
  7. int n = int.Parse(Console.ReadLine());
  8. int m = int.Parse(Console.ReadLine());
  9.  
  10. int leftSum =0;
  11. int rightSum=0;
  12.  
  13. for(int i=n; i<=m; i++)
  14. {
  15. int secondRightDigit = i%10;
  16. int remove1 = i/10;
  17. int firstRightDigit = remove1%10;
  18. int remove2 = remove1 /10;
  19. int midDigit = remove2%10;
  20. int remove3 = remove2/10;
  21. int secondLeftDigit = remove3%10;
  22. int remove4=remove3/10;
  23. int firstLeftDigit = remove4%10;
  24.  
  25. leftSum = firstLeftDigit + secondLeftDigit;
  26. rightSum = firstRightDigit + secondRightDigit;
  27.  
  28. if (leftSum == rightSum)
  29. {
  30. Console.Write(" "+i);
  31. }
  32. else if (leftSum > rightSum)
  33. {
  34. rightSum += midDigit;
  35. if (leftSum == rightSum)
  36. {
  37. Console.Write(" "+i);
  38. }
  39. }
  40. else if (leftSum < rightSum)
  41. {
  42. leftSum+=midDigit;
  43. if (leftSum == rightSum)
  44. {
  45. Console.Write(" "+i);
  46. }
  47. }
  48. leftSum=0;
  49. rightSum=0;
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement