You are on page 1of 4

#include <stdio.

h>
#include <conio.h>
#include< math.h>
void main()
{
float a,b,c,D,r1,r2,m,s;
clrscr();
printf("ENTER the coefficients of x2,x and constant\n");
scanf("%f%f%f",&a,&b,&c);
D=(b*b-4*a*c);
if(D>0)
{
printf("the roots are real and distinct");

r1=((-b+pow(D,0.5))/2*a);
r2=((-b-pow(D,0.5))/2*a);
printf("The roots are %f %f",r1,r2);
}
else

if(D==0)
{
printf("The roots are real and equal \n");
r1=(-b/(2*a));
r2=r1;
printf("the roots are %f,%f",r1,r2);
}
else

{
D=-D;
printf("the roots are imaginary");
m=(-b/(2*a));
s=(pow(D,.5)/(2*a));
printf("the roots are %f+i%f and %fi%f",m,s,m,s);
}
getch();
}
OUTPUT
ENTER the coefficients of x^2,x and constant
1 3 4

the roots are imaginary


the roots are -1.500000+i1.322876 and -1.500000-i1.322876

ENTER the coefficients of x2,x and constant


1 6 9
The roots are real and equal
the roots are -3.000000,-3.000000

You might also like