1036 Bhaskara's Formula

SemiColon
By -
0
URI Online Judge | 1036

Bhaskara's Formula

Read 3 floating-point numbers. After, print the roots of bhaskara’s formula. If it's impossible to calculate the roots because a division by zero or a square root of a negative number, presents the message “Impossivel calcular”.

Input

Read 3 floating-point numbers A, B and C.

Output

Print the result with 5 digits after the decimal point or the message if it is impossible to calculate.
Input SamplesOutput Samples
10.0 20.1 5.1R1 = -0.29788
R2 = -1.71212
0.0 20.0 5.0Impossivel calcular
10.3 203.0 5.0R1 = -0.02466
R2 = -19.68408
10.0 3.0 5.0Impossivel calcular


Solution:

#include<stdio.h>
#include <math.h>

int main()
{
 double a, b, c, t;
 scanf("%lf %lf %lf", &a, &b, &c);

 if(((b * b) - 4 * a * c) < 0 || a == 0){
     printf("Impossivel calcular\n");
 }
 else{
  t = sqrt((b * b) - 4 * a * c);
  printf("R1 = %.5lf\nR2 = %.5lf\n", ((-b + t) / (2 * a)), ((-b - t) / (2 * a)));
    }
 return 0;

}



Tags:

Post a Comment

0Comments

Post a Comment (0)