Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MonoDevelop
- using System;
- namespace GiaiPTBac2
- {
- class MainClass
- {
- public static void Main (string[] args)
- {
- float a, b, c, d, x1, x2;
- Console.WriteLine ("Giai Phuong Trinh Bac 2 ");
- Console.WriteLine ("Nhap a: ");
- a = float.Parse (Console.ReadLine ());
- Console.WriteLine ("Nhap b: ");
- b = float.Parse (Console.ReadLine ());
- Console.WriteLine ("Nhap c: ");
- c = float.Parse (Console.ReadLine ());
- d = b * b - 4 * a * c;
- if (a != 0) {
- if (d < 0) {
- Console.WriteLine ("PT vo nghiem");
- }
- if (d == 0) {
- x1 = -b / (2 * a);
- Console.WriteLine ("PT co nghiem kep x1 = x2 = {0}", x1);
- }
- if (d > 0) {
- Console.WriteLine ("PT co 2 nghiem phan biet");
- x1 = (-b + (float)Math.Sqrt (d)) / (2 * a);
- x2 = (-b - (float)Math.Sqrt (d)) / (2 * a);
- Console.WriteLine (" x1 = {0}", x1);
- Console.WriteLine (" x2 = {0}", x2);
- }
- } else {
- if (b != 0) {
- x1 = -c / b;
- Console.WriteLine ("PT co nghiem x = {0}", x1);
- } else {
- if (c != 0) {
- Console.WriteLine ("PT vo nghiem");
- } else {
- Console.WriteLine ("PT vo so nghiem");
- }
- }
- }
- Console.ReadLine ();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment