Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace DivisorsV1;
- static class Program
- {
- private static List<int> Divisors(int number)
- {
- List<int> divisor = new List<int>();
- foreach (int divisorNumber in Enumerable.Range(1, number))
- {
- divisor.Add(number % divisorNumber == 0 ? divisorNumber : -1);
- }
- divisor.RemoveAll(divisorNumber => divisorNumber == -1);
- return divisor;
- }
- private static void Main()
- {
- string? temp = Console.ReadLine();
- int number = int.TryParse(temp, out int num) ? num : 0;
- foreach (int divisor in Divisors(number).SkipLast(1))
- {
- Console.Write(divisor + ",");
- }
- Console.Write(number);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement