Facebook
From Reliable Kitten, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 159
  1. using System;
  2.  
  3. namespace Bartosz_Laskowski_Kolokwium_2
  4. {
  5.     class Program
  6.     {
  7.         static int dziel(int n)
  8.         {
  9.             for (int i = 1; i <= n; i++)
  10.             {
  11.                 if (n % i == 0)
  12.                 {
  13.                     Console.WriteLine(i);
  14.                 }
  15.             }
  16.             return 0;
  17.         }
  18.         static bool pier(int n)
  19.         {
  20.             bool test=false;
  21.             for(int i=2; i<n-1; i++)
  22.             {
  23.                 if(n%i==0)
  24.                 {
  25.                     test=true;
  26.                 }
  27.             }
  28.             if(test==true)
  29.             {
  30.                 return true;
  31.              }
  32.             else
  33.             {
  34.                 return false;
  35.             }
  36.         }
  37.  
  38.  
  39.         static void Main(string[] args)
  40.         {
  41.             Console.WriteLine("Program zrealizował Bartosz Laskowski");
  42.             uint wybor = 0;
  43.  
  44.             do
  45.             {
  46.                 wybor = 0;
  47.                 Console.WriteLine("1. Test metod");
  48.                 Console.WriteLine("2. Odczyt pliku i działanie");
  49.                 Console.WriteLine("3. Koniec");
  50.                 do
  51.                 {
  52.                     Console.WriteLine("Wybierz opcję:");
  53.                     if (uint.TryParse(Console.ReadLine(), out wybor)) ;
  54.                     else
  55.                     {
  56.                         Console.WriteLine("Podaj wartość liczbową");
  57.                     }
  58.                 }
  59.                 while (wybor > 3 || wybor < 1);
  60.                 switch (wybor)
  61.                 {
  62.                     case 1:
  63.                         int n;
  64.                         bool test = false;
  65.                         Console.WriteLine("\nPodaj liczbę naturalną");
  66.                         n = int.Parse(Console.ReadLine());
  67.                         Console.WriteLine("Twoja liczba to: {0}", n);
  68.                         Console.WriteLine("Dzielniki twojej liczby to: ");
  69.                         dziel(n);
  70.                         if(pier(n)==true)
  71.                         {
  72.                             Console.WriteLine("Twoja liczba nie jest pierwsza");
  73.                         }
  74.                         else
  75.                         {
  76.                             Console.WriteLine("Twoja liczba jest pierwsza");
  77.                         }
  78.                         break;
  79.  
  80.                     case 2:
  81.                         string text = System.IO.File.ReadAllText(@"C:\Users\barte\source\repos\Bartosz Laskowski Kolokwium 2\hasla.txt");
  82.                         Console.WriteLine(text);
  83.                         int ilosca = 0;
  84.                         for (int i = 0; i < text.Length; i++)
  85.                         {
  86.  
  87.                             if (text[i].CompareTo('a') == 0)
  88.                             {
  89.                                 ilosca++;
  90.                             }
  91.                         }
  92.                         Console.WriteLine("Ilość litery a w tym tekscie to {0}", ilosca);
  93.  
  94.  
  95.                         break;
  96.  
  97.  
  98.                     case 3:
  99.                         Console.WriteLine("Dziękuje za skorzystanie z programu");
  100.                         break;
  101.                     default:
  102.                         Console.WriteLine("Nie wybrałeś żadnej opcji. Spróbuj ponownie");
  103.                         break;
  104.                 }
  105.  
  106.  
  107.             }
  108.             while (wybor != 3);
  109.         }
  110.     }
  111. }
  112.