Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SpecialNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- string n = Console.ReadLine();
- for (int i = 1; i <= int.Parse(n); i++)
- {
- int sum = 0;
- int x = i;
- for (int j = 0; j < i.ToString().Length; j++)
- {
- sum += x % 10;
- x /= 10;
- }
- if (sum == 5 || sum == 7 || sum == 11)
- {
- Console.WriteLine($"{i} -> True");
- }
- else
- {
- Console.WriteLine($"{i} -> False");
- }
- }
- }
- }
- }
- Решение с LINQ:
- using System;
- using System.Linq;
- namespace SpecialNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- for (int i = 1; i <= n; i++)
- {
- int sum = i.ToString().Sum(a => (a - 48));
- Console.WriteLine($"{i} -> {sum == 5 || sum == 7 || sum == 11}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement