Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.16 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 ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string wybor;
  14.             do
  15.             {
  16.                 Console.WriteLine("Co chcesz zrobić A - f. kwadratowa, B - silnia, C - chce zakończyć program");
  17.                 wybor = Console.ReadLine();
  18.                 switch (wybor)
  19.                 {
  20.                     case "A":
  21.                         int a, b, c, delta;
  22.                         double x1, x2;
  23.                         Console.WriteLine("Podaj wartość a");
  24.                         bool oka = Int32.TryParse(Console.ReadLine(), out a);
  25.                         Console.WriteLine("Podaj wartość b");
  26.                         bool okb = Int32.TryParse(Console.ReadLine(), out b);
  27.                         Console.WriteLine("Podaj wartość c");
  28.                         bool okc = Int32.TryParse(Console.ReadLine(), out c);
  29.  
  30.                         if ((oka == true) && (okb == true) && (okc == true))
  31.                         {
  32.                             delta = b * b - (4 * a * c);
  33.                             Console.WriteLine("Delta wynosi: " + delta);
  34.                             if (delta > 0)
  35.                             {
  36.                                 x1 = (-b - Math.Sqrt(delta)) / (2 * a);
  37.                                 x2 = (-b + Math.Sqrt(delta)) / (2 * a);
  38.                                 Console.WriteLine("x1: " + x1 + " x2: " + x2);
  39.                             }
  40.                             else if (delta == 0)
  41.                             {
  42.                                 x1 = (-b - Math.Sqrt(delta)) / (2 * a);
  43.                                 Console.WriteLine("x1: " + x1);
  44.                             }
  45.                             else
  46.                             {
  47.                                 Console.WriteLine("Brak miejsc zerowych");
  48.                             }
  49.  
  50.                         }
  51.                         else
  52.                         {
  53.                             Console.WriteLine("Błąd podaj cyf");
  54.                         }
  55.  
  56.                         Console.ReadKey();
  57.                         break;
  58.  
  59.                     case "B":
  60.                         int liczba;
  61.                         int silnia = 1;
  62.                         Console.WriteLine("Podaj wartość a");
  63.                         bool okliczba = Int32.TryParse(Console.ReadLine(), out liczba);
  64.                         for (int i = 1; i <= liczba; i++)
  65.                         {
  66.                             silnia = silnia * i;
  67.                         }
  68.                         Console.WriteLine("Silnia liczby " + liczba + " wynosi: " + silnia);
  69.                         Console.ReadKey();
  70.                         break;
  71.                     case "C":
  72.                         break;// koniec petli
  73.                         break;// konciec case
  74.                     default:
  75.                         Console.WriteLine("zly wybor:P");
  76.                         break;
  77.                 }
  78.             }
  79.             while (wybor != "C");
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement