Advertisement
Guest User

03. Equal Sums

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