Advertisement
sellmmaahh

OR-tut3-zad3

Aug 5th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5.     float a, b, c;
  6.     float x1_re, x1_im;
  7.     float x2_re, x2_im;
  8.     float t, D;
  9.     printf("Unesite koeficijente kvadratne jednacine: ");
  10.     scanf("%f %f %f", &a, &b, &c);
  11.     D = b * b - 4.0f * a * c;
  12.  
  13.     while (D<0) {
  14.             printf("D je manje od 0. Unesite ponovo:");
  15.       scanf("%f %f %f", &a, &b, &c);
  16.          D = b * b - 4.0f * a * c;
  17.  
  18.     }
  19.      printf("Rjesenja su: \n");
  20.     if(D > 0.0f)
  21.     {
  22.         t = sqrt(D);
  23.         x1_re = (- b + t) / (2 * a);
  24.         x2_re = (- b - t) / (2 * a);
  25.         printf(" x1 = %f \n", x1_re);
  26.         printf(" x2 = %f \n", x2_re);
  27.     }
  28.     else if(D == 0.0f)
  29.     {
  30.         x1_re = - b / (2 * a);
  31.         printf(" x1 = x2 = %f \n", x1_re);
  32.     }
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement