atorresleticia

Bhaskara

Jun 7th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. float bhaskara (float a, float b, float c){
  5.  
  6. float x1, x2, delta;
  7.  
  8.    if (a==0){
  9.       printf ("Impossivel calcular.\n");
  10.    }else {
  11.       delta = ((b*b) - (4*a*c));
  12.          if (delta<0){
  13.             printf ("Raiz imaginaria.\n");
  14.          } else if (delta>0) {
  15.             x1 = (-b + (sqrt(delta)))/(2*a);
  16.             return x1;
  17.             x2 = (-b - (sqrt(delta)))/(2*a);
  18.             return x2;
  19.          } else if (delta==0) {
  20.             x1 = (-b + (sqrt(delta)))/(2*a);
  21.             x2 = (-b - (sqrt(delta)))/(2*a);
  22.             x1 = x2;
  23.          return x1;
  24.          }
  25.    }
  26.  
  27. }
  28. int main (){
  29.  
  30.    float x, y, z, raizes;
  31.    printf ("Digite tres numeros: ");
  32.    scanf ("%f %f %f", &x, &y, &z);
  33.    raizes = bhaskara(x, y, z);
  34.    printf ("A(s) raiz(es) e/sao: %f", raizes);
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment