Advertisement
salron3

Quadratic Equations

Oct 24th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     printf("Calculator for Quadratic Equations.Please enter values for a, b and c. \n");
  8.  
  9.     float a, b, c;
  10.     float x1, x2, d;
  11.    
  12.     printf("Enter a = ");
  13.     scanf("%g", &a);
  14.  
  15.     printf("Enter b = ");
  16.     scanf("%g", &b);
  17.  
  18.     printf("Enter c = ");
  19.     scanf("%g", &c);
  20.  
  21.     if (a == 0)
  22.     {
  23.         x1 = - c / b;
  24.         printf("x1 = %g\n", x1);
  25.     }
  26.     else if (b == 0)
  27.     {
  28.         if (-c / a < 0)
  29.         {
  30.             printf("Nqma reshenie\n");
  31.         }
  32.         else
  33.         {
  34.             x1 = sqrt(-c / a);
  35.             x2 = -1 * sqrt(-c / a);
  36.  
  37.             printf("x1 = %g\n", x1);
  38.             printf("x2 = %g\n", x2);
  39.         }
  40.        
  41.     }
  42.     else if (c == 0)
  43.     {
  44.         x1 = 0;
  45.         x2 = -b / a;
  46.  
  47.         printf("x1 = %g\n", x1);
  48.         printf("x2 = %g\n", x2);
  49.  
  50.     }
  51.     else
  52.     {
  53.         d = b*b - 4 * a*c;
  54.         if (d < 0)
  55.         {
  56.             printf("Nqma realni koreni\n");
  57.         }
  58.         else if (d == 0)
  59.         {
  60.             x1 = (-b) / (2 * a);
  61.             printf("x1 = x2 = %g\n", x1);
  62.         }
  63.         else
  64.         {
  65.             x1 = (-b + sqrt(d)) / (2 * a);
  66.             x2 = (-b - sqrt(d)) / (2 * a);
  67.  
  68.             printf("x1 = %g\n", x1);
  69.             printf("x2 = %g\n", x2);
  70.         }  
  71.     }
  72.  
  73.     system("PAUSE");
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement