ralichka

Nested.Loop.Exercises-04.Equal.Sums.Odd.Even.Positions-index

Jul 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.OtherVersion
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int num1 = int.Parse(Console.ReadLine());
  10.             int num2 = int.Parse(Console.ReadLine());
  11.  
  12.             int oddSum = 0;
  13.             int evenSum = 0;
  14.  
  15.             int numberAsInt = 0;
  16.  
  17.             for (int i = num1; i <= num2; i++)
  18.             {
  19.                 string currentNumber = i + ""; //правим го на стринг,
  20.                                                //за да измерим дължината
  21.                 for (int j = 0; j < currentNumber.Length; j++)
  22.                 {
  23.  
  24.  
  25.                     numberAsInt = int.Parse(currentNumber[j].ToString());
  26.  
  27.                     if (j % 2 == 0)
  28.                     {
  29.                        //numberAsInt = currentNumber[j];
  30.                         oddSum += numberAsInt;
  31.                     }
  32.                     else
  33.                     {
  34.                         evenSum += numberAsInt;
  35.                     }
  36.  
  37.                 }
  38.                     if (evenSum == oddSum)
  39.                     {
  40.                         Console.Write(currentNumber + " ");
  41.                     }
  42.                 oddSum = 0;
  43.                 evenSum = 0;
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment