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 Samples | Output Samples |
10.0 20.1 5.1 | R1 = -0.29788 R2 = -1.71212 |
0.0 20.0 5.0 | Impossivel calcular |
10.3 203.0 5.0 | R1 = -0.02466 R2 = -19.68408 |
10.0 3.0 5.0 | Impossivel calcular |
SOURCE CODE
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, r1, r2;
scanf("%f %f %f", & a, & b, & c);
d = (pow(b, 2) - (4 * a * c));
r1 = ((-b + sqrt(d)) / (2 * a));
r2 = ((-b - sqrt(d)) / (2 * a));
if (a != 0 && d > 0)
printf("R1 = %.5lf\nR2 = %.5lf\n", r1, r2);
else
printf("Impossivel calcular\n");
return 0;
}
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, r1, r2;
scanf("%f %f %f", & a, & b, & c);
d = (pow(b, 2) - (4 * a * c));
r1 = ((-b + sqrt(d)) / (2 * a));
r2 = ((-b - sqrt(d)) / (2 * a));
if (a != 0 && d > 0)
printf("R1 = %.5lf\nR2 = %.5lf\n", r1, r2);
else
printf("Impossivel calcular\n");
return 0;
}
No comments:
Post a Comment