Ziomnexpl

miejsca zerowe funkcji kwadratowej C#

Nov 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2.  
  3. namespace zsdfgh
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.Clear();
  10.             Console.WriteLine("program oblicza miejsca zerowe według funkcji ax2+b");
  11.             Console.Write("podaj a= ");
  12.             float a = 1;
  13.             float b = 1;
  14.             float c = 1;
  15.             a = float.Parse(Console.ReadLine());
  16.             Console.Write("podaj b= ");
  17.             b = float.Parse(Console.ReadLine());
  18.             Console.Write("podaj c= ");
  19.             c = float.Parse(Console.ReadLine());
  20.             if (a == 0)
  21.             {
  22.                 Console.WriteLine("a nie może być równe 0");
  23.                 return;
  24.             }
  25.             float delta;
  26.             delta = (b * b) - 4 * a * c;
  27.             Console.Write("delta = " + delta);
  28.             if (delta == 0)
  29.             {
  30.                 float x;
  31.                 x = -b / (2 * a);
  32.                 Console.WriteLine(x);
  33.             }
  34.             if (delta < 0)
  35.             {
  36.                 Console.WriteLine("Brak miejsc zerowych");
  37.             }
  38.  
  39.             if (delta > 0)
  40.             {
  41.                 double x1, x2;
  42.                 double pierwiastek_delta = Math.Sqrt(delta);
  43.                 x1 =( (-b) - (pierwiastek_delta / (2 * a)));
  44.                 x2 =( (-b) + (pierwiastek_delta / (2 * a)));
  45.                 Console.WriteLine("x1 = " + x1);
  46.                 Console.WriteLine("x2 = " + x2);
  47.             }
  48.             Console.ReadKey();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment