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 ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int a, b, c, x;
- // Console.WriteLine("Введіть коєф. рівняння");
- string[] o = Console.ReadLine().Split(' ');
- a = Convert.ToInt32(o[0]);
- b = Convert.ToInt32(o[1]);
- c = Convert.ToInt32(o[2]);
- //Console.WriteLine("Ви задали рівняння:{0}x*x+{1}x+{2}=0", a, b, c);
- int d = b * b - 4 * a * c;
- //Console.WriteLine("Дискримінант = " + d);
- if (d > 0)
- {
- double x1, x2;
- x1 = (-b + Math.Sqrt(d)) / (2 * a);
- x2 = (-b - Math.Sqrt(d)) / (2 * a);
- if (x1 > x2)
- {
- Console.WriteLine("Two roots: " + x2 + " " + x1);
- }
- else
- {
- Console.WriteLine("Two roots: " + x1 + " " + x2);
- }
- //Console.WriteLine("One roots: " + x1);
- //Console.WriteLine("Two roots: " + x2);
- }
- else if(d==0)
- {
- x = (-b / (2 * a));
- Console.WriteLine("One root: " + x);
- }
- else
- {
- Console.WriteLine("No roots");
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement