Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float bhaskara (float a, float b, float c){
- float x1, x2, delta;
- if (a==0){
- printf ("Impossivel calcular.\n");
- }else {
- delta = ((b*b) - (4*a*c));
- if (delta<0){
- printf ("Raiz imaginaria.\n");
- } else if (delta>0) {
- x1 = (-b + (sqrt(delta)))/(2*a);
- return x1;
- x2 = (-b - (sqrt(delta)))/(2*a);
- return x2;
- } else if (delta==0) {
- x1 = (-b + (sqrt(delta)))/(2*a);
- x2 = (-b - (sqrt(delta)))/(2*a);
- x1 = x2;
- return x1;
- }
- }
- }
- int main (){
- float x, y, z, raizes;
- printf ("Digite tres numeros: ");
- scanf ("%f %f %f", &x, &y, &z);
- raizes = bhaskara(x, y, z);
- printf ("A(s) raiz(es) e/sao: %f", raizes);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment