Guest User

Untitled

a guest
Mar 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ConsoleApp11
  10. {
  11. public class Program
  12. {
  13. static StreamReader Reader = new StreamReader(@"C:\liczby.csv"); // Strumień danych
  14. static List<int> ListaCSV = new List<int>();
  15. static List<int> Listalol = new List<int>();
  16. static int licznik = 1;
  17.  
  18.  
  19. public static void Main()
  20. {
  21.  
  22.  
  23.  
  24. Thread t1 = new Thread(new ThreadStart(Liczbycsv));
  25. Thread t2 = new Thread(new ThreadStart(Progressj));
  26.  
  27. t1.IsBackground = true;
  28. t2.IsBackground = true;
  29.  
  30. Console.ForegroundColor = ConsoleColor.Cyan;
  31. Console.WriteLine("Szukam liczb doskonałych || ESC - Przerwij program");
  32. Console.ResetColor();
  33.  
  34.  
  35.  
  36. t1.Start();
  37. t2.Start();
  38.  
  39.  
  40.  
  41.  
  42. if (Console.ReadKey(true).Key == ConsoleKey.Enter)
  43. {
  44. Console.WriteLine("Enter");
  45. Environment.Exit(0);
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52. }
  53.  
  54. public static void Liczbycsv()
  55. {
  56. #region Ładowanie danych
  57.  
  58.  
  59.  
  60. while (!Reader.EndOfStream) //
  61. {
  62. var liczby = int.Parse((Reader.ReadLine()));
  63. ListaCSV.Add(liczby);
  64. }
  65.  
  66.  
  67. #endregion
  68.  
  69.  
  70.  
  71.  
  72. for (int x = 0; x < ListaCSV.Count; x++)
  73. {
  74. licznik = x;
  75.  
  76. int suma = 0;
  77. for (int i = 1; i < ListaCSV[x]; i++)
  78. {
  79. if (ListaCSV[x] % i == 0)
  80. {
  81. suma += i;
  82.  
  83. }
  84.  
  85. }
  86.  
  87.  
  88.  
  89. if (suma == ListaCSV[x])
  90. {
  91.  
  92. Console.WriteLine($"Liczba {ListaCSV[x]} jest liczbą doskomałą || na pozycji nr {x + 1}");
  93. Listalol.Add(suma);
  94.  
  95. }
  96.  
  97.  
  98.  
  99. }
  100. Console.WriteLine($"Suma wszystkie liczb doskonałych wynosi: {Listalol.Sum()}");
  101.  
  102.  
  103. }
  104.  
  105. public static void Progressj()
  106. {
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. }
  118. }
  119.  
  120.  
  121. }
Add Comment
Please, Sign In to add comment