Advertisement
Jvsierra

Eq ref

Jun 22nd, 2018
104
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 <conio.h>
  3. #include <math.h>
  4.  
  5. int raizes (float a, float b, float c, float * x1, float * x2);
  6.  
  7. int main()
  8. {
  9.     float a, b, c, r1, r2;
  10.     int num;
  11.    
  12.     scanf("%f %f %f", &a, &b, &c);
  13.    
  14.     num = raizes(a, b, c, &r1, &r2);
  15.    
  16.     if(num == 0)
  17.         printf("Nenhuma raiz real\n");
  18.     else if(num == 1)
  19.     {
  20.         printf("X1 = X2 = %f\n", r1);
  21.     }
  22.     else
  23.     {
  24.         printf("X1 = %f\n", r1);
  25.         printf("X2 = %f\n", r2);
  26.     }
  27.    
  28.     getch();
  29. }
  30.  
  31. int raizes(float a, float b, float c, float * x1, float * x2)
  32. {
  33.     float delta = pow(b, 2) - 4 * a * c;
  34.    
  35.     if(delta < 0)
  36.         return 0;
  37.     else if(delta == 0)
  38.     {
  39.         *x1 = (b * -1 + sqrt(delta)) / (2 * a);
  40.         return 1;
  41.     }
  42.     else
  43.     {
  44.         *x1 = (b * -1 + sqrt(delta)) / (2 * a);
  45.         *x2 = (b * -1 - sqrt(delta)) / (2 * a);
  46.         return 2;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement