Find the real root of a quadratic equation
/*WAP to find the
real root of a quadratic equation*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float
a,b,c,d,r1,r2;
clrscr();
printf("enter
the value of a,b and c:");
scanf("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)
printf("UNREAL
ROOT");
else if(d==0)
{
r1=r2=-b/2*a;
printf("real
roots are %.2f and %.2f",r1,r2);
}
else
{
r1=(-b+sqrt(d))/2*a;
r2=(-b-sqrt(d))/2*a;
printf("real
roots are %.2f and %.2f",r1,r2);
}
getch();
}
OUTPUT:
enter the value
of a,b and c:1 4 3
real roots are
-1.00 and -3.00
No comments:
Post a Comment