Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace EqualSumsEvenOddPosition
- {
- class Program
- {
- static void Main(string[] args)
- {
- int start = int.Parse(Console.ReadLine());
- int final = int.Parse(Console.ReadLine());
- for (int i = start; i <= final; i++)
- {
- int odd = 0;
- int even = 0;
- int digit = i;
- for (int x = 0; x < 6; x++)
- {
- if (x % 2 == 0)
- {
- even += digit % 10;
- }
- else
- {
- odd += digit % 10;
- }
- digit /= 10;
- }
- if (odd == even)
- {
- Console.Write(i + " ");
- }
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace EqualSumsEvenOddPosition
- {
- class Program
- {
- static void Main(string[] args)
- {
- int start = int.Parse(Console.ReadLine());
- int final = int.Parse(Console.ReadLine());
- for (int i = start; i <= final; i++)
- {
- int odd = 0;
- int even = 0;
- int digit = i;
- for (int x = 0; x < 6; x++)
- {
- _ = x % 2 == 0 ? even += digit % 10 : odd += digit % 10;
- digit /= 10;
- }
- Console.Write(odd == even ? i + " " : "");
- }
- }
- }
- }
- РЕШЕНИЕ С ТО.STRING():
- using System;
- namespace EqualSumsEvenOddPosition
- {
- class Program
- {
- static void Main(string[] args)
- {
- int start = int.Parse(Console.ReadLine());
- int final = int.Parse(Console.ReadLine());
- for (int i = start; i <= final; i++)
- {
- int odd = 0;
- int even = 0;
- string current = i.ToString();
- for (int x = 0; x < current.Length; x++)
- {
- int digit = int.Parse(current[x].ToString());
- if (x % 2 == 0)
- {
- even += digit;
- }
- else
- {
- odd += digit;
- }
- }
- if (odd == even)
- {
- Console.Write(i + " ");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment