Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ConsoleApp11
- {
- public class Program
- {
- static StreamReader Reader = new StreamReader(@"C:\liczby.csv"); // Strumień danych
- static List<int> ListaCSV = new List<int>();
- static List<int> Listalol = new List<int>();
- static int licznik = 1;
- public static void Main()
- {
- Thread t1 = new Thread(new ThreadStart(Liczbycsv));
- Thread t2 = new Thread(new ThreadStart(Progressj));
- t1.IsBackground = true;
- t2.IsBackground = true;
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("Szukam liczb doskonałych || ESC - Przerwij program");
- Console.ResetColor();
- t1.Start();
- t2.Start();
- if (Console.ReadKey(true).Key == ConsoleKey.Enter)
- {
- Console.WriteLine("Enter");
- Environment.Exit(0);
- }
- }
- public static void Liczbycsv()
- {
- #region Ładowanie danych
- while (!Reader.EndOfStream) //
- {
- var liczby = int.Parse((Reader.ReadLine()));
- ListaCSV.Add(liczby);
- }
- #endregion
- for (int x = 0; x < ListaCSV.Count; x++)
- {
- licznik = x;
- int suma = 0;
- for (int i = 1; i < ListaCSV[x]; i++)
- {
- if (ListaCSV[x] % i == 0)
- {
- suma += i;
- }
- }
- if (suma == ListaCSV[x])
- {
- Console.WriteLine($"Liczba {ListaCSV[x]} jest liczbą doskomałą || na pozycji nr {x + 1}");
- Listalol.Add(suma);
- }
- }
- Console.WriteLine($"Suma wszystkie liczb doskonałych wynosi: {Listalol.Sum()}");
- }
- public static void Progressj()
- {
- }
- }
- }
Add Comment
Please, Sign In to add comment