madeofglass

Untitled

Feb 16th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02.EqualSumsEvenOddPosition
  4. {
  5.     class EqualSumsEvenOddPosition
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int firstNum = int.Parse(Console.ReadLine());
  10.             int secondNum = int.Parse(Console.ReadLine());
  11.  
  12.             for (int i = firstNum; i <= secondNum; i++)
  13.             {
  14.                 string currentNum = i.ToString();
  15.                 //Console.WriteLine(currentNum);
  16.  
  17.                 int oddSum = 0;
  18.                 int evenSum = 0;
  19.  
  20.                 for (int j = 0; j < currentNum.Length; j++)
  21.                 {
  22.                     int currentDigit = int.Parse(currentNum[j].ToString());
  23.  
  24.                     if (j % 2 == 0)
  25.                     {
  26.                         evenSum += currentDigit;
  27.                     }
  28.                     else
  29.                     {
  30.                         oddSum += currentDigit;
  31.                     }
  32.                 }
  33.                 if (oddSum == evenSum)
  34.                 {
  35.                     Console.Write(i + " ");
  36.                 }
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment