Для каждого натурального числа в промежутке от m до n вывести все делители, кроме единицы и самого числа. m и n вводятся с клавиатуры — С#(Си шарп)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int m = GetData("M: ");
int n = GetData("N: ");
  
if (n < m)
    throw new ArgumentOutOfRangeException();
  
Console.WriteLine("\nЧисло\t\t\tДелители");
for (int i = m; i <= n; i++)
{
    int[] divisors = GetDivisors(i);
    Console.WriteLine($"{i}\t\t\t{string.Join(" ", divisors)}");
}
  
  
int[] GetDivisors(int number)
{
    int[] result = new int[0];
    for (int i = 2; i < number; i++)
        if (number % i == 0)
        {
            Array.Resize(ref result, result.Length + 1);
            result[result.Length - 1] = i;
        }
  
    return result;
}
  
int GetData(string q)
{
    Console.Write(q);
    return Convert.ToInt32(Console.ReadLine());
}

Leave a Comment