Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Division
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- int output = 0;
- if (num % 10 == 0)
- {
- output = 10;
- }
- else if (num % 7 == 0)
- {
- output = 7;
- }
- else if (num % 6 == 0)
- {
- output = 6;
- }
- else if (num % 3 == 0)
- {
- output = 3;
- }
- else if (num % 2 == 0)
- {
- output = 2;
- }
- if (output != 0)
- {
- Console.WriteLine($"The number is divisible by {output}");
- }
- else
- {
- Console.WriteLine("Not divisible");
- }
- }
- }
- }
- Решение с тернарен оператор:
- using System;
- namespace Division
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- string output =
- num % 10 == 0 ? "10" :
- num % 7 == 0 ? "7" :
- num % 6 == 0 ? "6" :
- num % 3 == 0 ? "3" :
- num % 2 == 0 ? "2" : "Not divisible";
- Console.WriteLine(output == "Not divisible" ? "Not divisible" : $"The number is divisible by {output}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement