Skip to main content

C Program to calculate roots of quadratic equations

C Program to calculate roots of quadratic equations
This is a simple C program to calculate roots of quadratic equations.A function sqrt() is used in this program to find the square root.Also, we will have to include the math.h header.





#include
#include
main()
{
int a,b,c,d;
float root1,root2;
printf("Enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
root1=((-b)+sqrt(d))/(2*a);
root2=((-b)-sqrt(d))/(2*a);
printf("root1=%f and root2=%f",root1,root2);
}





Comments

Unknown said…
thank you very much for this easy program !!, this helped me in my exam !! thanx !
G.K. said…
Thanks for the appreciation,
please help me making this blog more useful by posting your comments and suggestions.
Vignesh said…
Thank you very much sir
G.K. said…
thanx for reading,
your comments and suggestions are welcome.
Anonymous said…
hear what's about d..
Hasna Farzana said…
THANK YOU SO MUCH
I WAS VERY HAPPY ABOUT THIS...THANK YOU SO SO MUCH!!!!!
YAHOOOOOO I FINALLY GOT IT
Hasna Farzana said…
THANK YOU SO MUCH
I WAS VERY HAPPY ABOUT THIS...THANK YOU SO SO MUCH!!!!!
YAHOOOOOO I FINALLY GOT IT
surendra said…
but if discriminant is is negative then this program is valid?
sudhir rajput said…
thanks to help me...