Advertisement
angryatti

Divisors Dont learn it, it was made for fun

Jan 16th, 2025 (edited)
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | Source Code | 0 0
  1. namespace DivisorsV1;
  2.  
  3. static class Program
  4. {
  5.     private static List<int> Divisors(int number)
  6.     {
  7.         List<int> divisor = new List<int>();
  8.  
  9.         foreach (int divisorNumber in Enumerable.Range(1, number))
  10.         {
  11.             divisor.Add(number % divisorNumber == 0 ? divisorNumber : -1);
  12.         }
  13.         divisor.RemoveAll(divisorNumber => divisorNumber == -1);
  14.        
  15.         return divisor;
  16.     }
  17.  
  18.     private static void Main()
  19.     {
  20.         string? temp = Console.ReadLine();
  21.         int number = int.TryParse(temp, out int num) ? num : 0;
  22.         foreach (int divisor in Divisors(number).SkipLast(1))
  23.         {
  24.             Console.Write(divisor + ",");
  25.         }
  26.         Console.Write(number);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement