Advertisement
EvgeniiKraaaaaaaav

1.8(quadratic equation)

Dec 5th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.08 KB | None | 0 0
  1. //https://vk.com/evgenykravchenko0
  2.  
  3.                 ___                                        ___                   ___    
  4.                /  /\                  ___                 /  /\                 /  /\    
  5.               /  /:/_                /__/\               /  /:/_               /  /:/_  
  6.              /  /:/ /\               \  \:\             /  /:/ /\             /  /:/ /\  
  7.             /  /:/ /:/_               \  \:\           /  /:/_/::\           /  /:/ /:/_
  8.            /__/:/ /:/ /\          ___  \__\:\         /__/:/__\/\:\         /__/:/ /:/ /\
  9.            \  \:\/:/ /:/         /__/\ |  |:|         \  \:\ /~~/:/         \  \:\/:/ /:/
  10.             \  \::/ /:/          \  \:\|  |:|          \  \:\  /:/           \  \::/ /:/
  11.              \  \:\/:/            \  \:\__|:|           \  \:\/:/             \  \:\/:/  
  12.               \  \::/              \__\::::/             \  \::/               \  \::/  
  13.                \__\/                   ~~~~               \__\/                 \__\/    
  14.                             ___                                            
  15.                            /__/\                ___                 ___    
  16.                            \  \:\              /  /\               /  /\    
  17.                             \  \:\            /  /:/              /  /:/    
  18.                         _____\__\:\          /__/::\             /__/::\    
  19.                        /__/::::::::\         \__\/\:\__          \__\/\:\__
  20.                        \  \:\~~\~~\/            \  \:\/\            \  \:\/\
  21.                         \  \:\  ~~~              \__\::/             \__\::/
  22.                          \  \:\                  /__/:/              /__/:/
  23.                           \  \:\                 \__\/               \__\/  
  24.                            \__\/                                            
  25.  #include <stdio.h>
  26. #include <math.h>
  27. int main()
  28. {
  29.   float a; // 1-й коэффициент
  30.   float b; // 2-ой коэффициент
  31.   float c; // Свободный коэффициент
  32.   float D = 0; // Дискриминант
  33.   float x1 = 0;// 1-й корень уравнения
  34.   float x2 = 0;// 2-ой корень уравнения
  35. //ax^2 + bx + c = 0
  36.   printf("Введите коэффициет а : ");
  37.   scanf("%f", &a);
  38.  
  39.   printf("Введите коэффициет b : ");
  40.   scanf("%f", &b);
  41.  
  42.   printf("Введите коэффициет c : ");
  43.   scanf("%f", &c);
  44.  
  45.   if (a == 0) exit(0);
  46. //break;
  47.  
  48.   if (a != 0 && b != 0 && c != 0)
  49.   {
  50.     D = b * b - 4 * a * c;
  51.     if (D < 0) exit(0);
  52. //break;
  53.     x1 = (-b + sqrt(D)) / (2 * a);
  54.     x2 = (-b - sqrt(D)) / (2 * a);
  55.   }
  56.   if (b == 0 && c == 0)
  57.   {                     //ax^2 = 0
  58.     x1 = 0;
  59.     x2 = 0;
  60.   }
  61.   else if (b == 0 || c == 0)
  62.   {
  63.     if (c == 0)
  64.     {                   //ax^2 + bx = 0
  65.       x1 = 0;
  66.       x2 = -b / a;
  67.     }
  68.     else if (b == 0)
  69.          {               //ax^2 + c = 0
  70.            x1 = sqrt(-c / a);
  71.            x2 = -sqrt(-c / a);
  72.          }
  73.   }
  74.  
  75.  
  76.   printf("x1 = %f \n", x1);
  77.   printf("x2 = %f \n", x2);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement