Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 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 masodfokumegoldo
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string s;
  14.             double a, b, c, eredmeny1,eredmeny2;
  15.             Console.WriteLine("x^2 eggyütthato: ");
  16.             s = Console.ReadLine();                         // String beolvasása
  17.             //a = Convert.ToInt16(s);                       // Átkonvertálása számmá
  18.             if (!double.TryParse(s, out a))                    // "a" változóba adja vissza az értéket, ha igaz, ha nem akkor
  19.             {
  20.                 Console.WriteLine("Ez nem szám");
  21.                 Console.ReadLine();
  22.                 return;
  23.             }
  24.             Console.WriteLine("x együtthato: ");
  25.             s = Console.ReadLine();
  26.             if (!double.TryParse(s, out b))
  27.             {
  28.                 Console.WriteLine("Ez nem szám");
  29.                 Console.ReadLine();
  30.                 return;
  31.             }
  32.  
  33.             Console.WriteLine("konstans: ");
  34.             s = Console.ReadLine();
  35.             if (!double.TryParse(s, out c))
  36.             {
  37.                 Console.WriteLine("Ez nem szám");
  38.                 Console.ReadLine();
  39.                 return;
  40.             }
  41.             if(a!=0)
  42.             {
  43.                 eredmeny1 = ((-b + Math.Sqrt((b * b) - 4 * a * c)) / 2 * a);
  44.                 eredmeny2 = ((-b - Math.Sqrt((b * b) - 4 * a * c)) / 2 * a);
  45.                 if ((b * b) - 4 * a * c<0)
  46.                 {
  47.                     Console.WriteLine("a gyök komplex!");
  48.                 }else
  49.                 {
  50.                     Console.WriteLine("Eredmény 1: {0} ", eredmeny1);
  51.                     Console.WriteLine("Eredmény 2: {0} ", eredmeny2);
  52.                 }
  53.                
  54.                 Console.ReadLine();
  55.             }else
  56.             {
  57.                 eredmeny1 = -c / b;
  58.                 eredmeny2 = -c / b;
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement