Advertisement
mmayoub

Ex, Mo3adala Tarbe3ia

Sep 20th, 2021
1,594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Mo3adalaTarbe3ia
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double a;
  10.             double b;
  11.             double c;
  12.             Console.WriteLine("enter a,b,c");
  13.             a = double.Parse(Console.ReadLine());
  14.             b = double.Parse(Console.ReadLine());
  15.             c = double.Parse(Console.ReadLine());
  16.  
  17.             if (a == 0)
  18.             {
  19.                 Console.WriteLine("Error, 'A' should not be zero");
  20.             }
  21.             else
  22.             {
  23.                 double delta = b * b - 4 * a * c;
  24.                 if (delta == 0)
  25.                 {
  26.                     // one solution
  27.                     Console.WriteLine("Your numbers have 1 Solution ");
  28.                     //double sol = -b / 2 * a;
  29.                     Console.WriteLine("x1 = {0}", -b / 2 * a);
  30.                 }
  31.                 else
  32.                 {
  33.                     if (delta > 0)
  34.                     {
  35.                         // two solutions
  36.                         Console.WriteLine("Your numbers have 2 Solutions ");
  37.  
  38.                         double deltasqrt = Math.Sqrt(delta);
  39.                         double x1 = (-b + deltasqrt) / (2 * a);
  40.                         double x2 = (-b - deltasqrt) / (2 * a);
  41.  
  42.                         Console.WriteLine("x1 = {0:f2}", x1);
  43.                         Console.WriteLine("x2 = {0:f2}", x2);
  44.                     }
  45.                     else
  46.                     {
  47.                         if (delta < 0)
  48.                         {
  49.                             Console.WriteLine("Your numbers have no Solutions ");
  50.                         }
  51.  
  52.                     }
  53.                 }
  54.  
  55.                 // min or max point
  56.                 double x = -b / (2 * a);
  57.                 double y = a * x * x + b * x + c;
  58.                 String st;
  59.                 if (a > 0)
  60.                 {
  61.                     st = "min";
  62.                 }
  63.                 else
  64.                 {
  65.                     st = "max";
  66.                 }
  67.                 Console.WriteLine("{0} = ({1}, {2})", st, x, y);
  68.                 //Console.WriteLine("{0} = ({1}, {2})", a > 0 ? "min" : "max", x, y);
  69.             }
  70.         }
  71.     }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement