Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Korki
  8. {
  9.     class Program
  10.     {
  11.         static int minmalValue = 0;
  12.         static int maximalValue = 1000000;
  13.         static int value;
  14.         static void Main(string[] args)
  15.         {
  16.             Console.WriteLine($"Podaj liczbę z zakresu {minmalValue} do {maximalValue}");
  17.  
  18.             while (true)
  19.             {
  20.                 var enter = Console.ReadLine();
  21.                 var result = CheckEnter(enter);
  22.                 if (result)
  23.                 {
  24.                     break;
  25.                 }
  26.                 else {
  27.                     Console.WriteLine("Zła liczba podaj nową.");
  28.                 }
  29.             }
  30.  
  31.             var array = GetAllocators(value);
  32.  
  33.             for (int i = 0; i < array.Length; i++)
  34.             {
  35.                 Console.WriteLine(array[i]);
  36.             }
  37.  
  38.             Console.ReadKey();
  39.         }
  40.  
  41.         static bool CheckEnter(string enter)
  42.         {
  43.             int result;
  44.             var succeeded = int.TryParse(enter, out result);
  45.             if (succeeded)
  46.             {
  47.                 if (result > minmalValue && result < maximalValue)
  48.                 {
  49.                     value = result;
  50.                     return true;
  51.                 }
  52.                 else
  53.                 {
  54.                     return false;
  55.                 }
  56.             }
  57.             else
  58.             {
  59.                 return false;
  60.             }
  61.         }
  62.  
  63.         static int[] GetAllocators(int value)
  64.         {
  65.             var counter = 0;
  66.             var temp = new int[value];
  67.             for (int i = 1; i <= value; i++)
  68.             {
  69.                 var res = value % i;
  70.                 if (res == 0)
  71.                 {
  72.                     temp[counter] = i;
  73.                     counter++;
  74.                 }
  75.             }
  76.  
  77.             return temp;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement