#include <stdio.h> #include <math.h> /* find the roots of the equation ax^2 + bx + c */ int main (){ float a,b,c,discriminant,root1,root2; printf ( "Enter a, b and c of quadratic equation: " ); scanf ( "%f%f%f" ,&a,&b,&c); discriminant = b * b - 4 * a * c; if (discriminant < 0 ) { printf ( "Roots are complex number. \n " ); printf ( "Roots of quadratic equation are: " ); printf ( "%.f%+.fi" ,-b/( 2 *a), sqrt (-discriminant)/( 2 *a)); printf ( ", %.f%+.fi" ,-b/( 2 *a),- sqrt (-discriminant)/( 2 *a)); return 0 ; } else if (discriminant== 0 ) { printf ( "Both roots are equal. \n " ); root1 = -b /( 2 * a); printf ( "Root of quadratic equation is: %.f " ,root1); return 0 ; } else if (discriminant > 0 ) { printf ( "Roots are real numbers. \n " ); root
Comments
Post a Comment