/*Write a C program to print
the roots of Bhaskara’s
formula from the given three
floating numbers. Display a
message if it is not possible
to find the roots.
Test Data :
Input the first number(a): 25
Input the second number(b): 35
Input the third number(c): 12
Expected Output:
Root1 = -0.60000
Root2 = -0.80000
*/
#include <stdio.h>
#include <math.h>
int main()
{
float a,b,c,r1,r2,d;
printf("Input the first num\
ber: ");
scanf("%f",&a);
printf("Input the second\
number: ");
scanf("%f",&b);
printf("Input the third\
number: ");
scanf("%f",&c);
d=sqrt((b*b)-(4*a*c));
r1=(-b+d)/(2*a);
r2=(-b-d)/(2*a);
printf("Root1 = %.5f\n",r1);
printf("Root2 = %.5f\n",r2);
}
No comments:
Post a Comment