Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace masodfokumegoldo
- {
- class Program
- {
- static void Main(string[] args)
- {
- string s;
- double a, b, c, eredmeny1,eredmeny2;
- Console.WriteLine("x^2 eggyütthato: ");
- s = Console.ReadLine(); // String beolvasása
- //a = Convert.ToInt16(s); // Átkonvertálása számmá
- if (!double.TryParse(s, out a)) // "a" változóba adja vissza az értéket, ha igaz, ha nem akkor
- {
- Console.WriteLine("Ez nem szám");
- Console.ReadLine();
- return;
- }
- Console.WriteLine("x együtthato: ");
- s = Console.ReadLine();
- if (!double.TryParse(s, out b))
- {
- Console.WriteLine("Ez nem szám");
- Console.ReadLine();
- return;
- }
- Console.WriteLine("konstans: ");
- s = Console.ReadLine();
- if (!double.TryParse(s, out c))
- {
- Console.WriteLine("Ez nem szám");
- Console.ReadLine();
- return;
- }
- if(a!=0)
- {
- eredmeny1 = ((-b + Math.Sqrt((b * b) - 4 * a * c)) / 2 * a);
- eredmeny2 = ((-b - Math.Sqrt((b * b) - 4 * a * c)) / 2 * a);
- if ((b * b) - 4 * a * c<0)
- {
- Console.WriteLine("a gyök komplex!");
- }else
- {
- Console.WriteLine("Eredmény 1: {0} ", eredmeny1);
- Console.WriteLine("Eredmény 2: {0} ", eredmeny2);
- }
- Console.ReadLine();
- }else
- {
- eredmeny1 = -c / b;
- eredmeny2 = -c / b;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement