Advertisement
zaqs114

Untitled

Oct 21st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. float a,b,c,x1,x2,d,pd,z;
  4. char L;
  5. int main()
  6. {
  7.     scanf ("%f %f %f", &a, &b, &c);
  8.     kwadratowa ();
  9.     return 0;
  10. }
  11. void kwadratowa ()
  12.     {
  13.         if (a==0 && b==0 && c==0)
  14.         {
  15.             printf("R");
  16.             return 0;
  17.         }
  18.         if (a==0 && b==0)
  19.         {
  20.             printf("0");
  21.             return 0;
  22.         }
  23.         if (a!=0)
  24.         {
  25.             d=(b*b)-(4*a*c);
  26.             pd=sqrt(d);
  27.             x1=(-b-pd)/(2*a);
  28.             x2=(-b+pd)/(2*a);
  29.             if (d>0)
  30.             {
  31.                 L='2';
  32.                     if (x1>x2)
  33.                     {
  34.                         z=x1;
  35.                         x1=x2;
  36.                         x2=z;
  37.                     }
  38.                 printf("%c %.1f %.1f", L, x1, x2);
  39.             }
  40.             if (d<0)
  41.             {
  42.                 L='R';
  43.                 printf("%c", L);
  44.             }
  45.             if (d==0)
  46.             {
  47.                 L='1';
  48.                 printf("%c %.1f", L, x1);
  49.             }
  50.         }
  51.         else
  52.         {
  53.             x1= -c/b;
  54.             L='1';
  55.             printf ("%c %.1f", L, x1);
  56.         }
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement