YouTip LogoYouTip

C Examples Quadratic Roots

# C Programming Example - Quadratic Equation [![Image 1: C Programming Example](#) C Programming Example](#) Find the roots of the quadratic equation: **axΒ² + bx + c = 0**. Input three real numbers a, b, c, where a is not equal to 0. ## Example #include#includeint main(){float a,b,c,x1,x2,d; printf("Enter the three coefficients of the equation:"); scanf("%f %f %f",&a,&b,&c); if(a!=0){d=sqrt(b*b-4*a*c); x1=(-b+d)/(2*a); x2=(-b-d)/(2*a); if(x1<x2)printf("%0.2f %0.2fn",x2,x1); else printf("%0.2f %0.2fn",x1,x2); }return 0; } Output: Enter the three coefficients of the equation:1 2 1-1.00 -1.00 [![Image 2: C Programming Example](#) C Programming Example](#)
← C Examples Negative Positive ZC Examples Vowel Consonant β†’