ProAnswers.org

Write a C program to find out the Roots of Quadratic Equation?

#include

#include



#include



void main()



{



int a,b,c,d;



float x1,x2;



clrscr();



printf(“

enter the values of a,b,c
”);

scanf(“%d%d%d”,&a,&b,&c);



d=b*b-4*a*c;



if(d==0)



{



printf(“

the roots are real and equal”);

x1=-b/(2*a);



printf(“%f

”,x1);

}



else if(d<0)



{



printf(“

the roots are imaginary
”);

x1=-b/(2*a);



x2=sqrt(-d)/(2*a);



printf(“%2f+i%2f

”,x1,x2);

printf(“%2f-i%2f

”,x1,x2);

}



else



{



printf(“

the roots are real and distinct”);

x1=-b+sqrt(d)/(2*a);



x2=-b-sqrt(d)/(2*a);



printf(“

%f
%f”,x1,x2);

}



getch();



}



[b]Output: [/b]



enter the values of a,b,c



2



8



3



the roots are real and distinct



-6.418861



-9.581139