Write a program to find real roots of quadratic equation.
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c,D;
float x1,x2,x;
printf("Enter Co-officiant of x^2 : ");
scanf("%d",&a);
printf("Enter Co-officiant of x : ");
scanf("%d",&b);
printf("Enter Constant : ");
scanf("%d",&c);
D=(b*b)-(4*a*c);
if(D == 0)
{
x=(-b)/(2.0*a);
printf("x = %.2f",x);
}
else if(D > 0)
{
x1= (-b+sqrt(D))/(a*2.0);
x2= (-b-sqrt(D))/(a*2.0);
printf("\nx = %.2f OR",x1);
printf(" x = %.2f",x2);
}
else
{
printf("Roots are complex");
}
}
0 Comments