text: Program to find the Roots of Quadratic equation | C program to find roots of a quadratic equation ; Prints roots of quadratic equation ax * 2 + bx + x ; If a is 0 , then equation is not quadratic , but linear ; else d < 0 ; Driver code ; Function call
code: #include <math.h> NEW_LINE #include <stdio.h> NEW_LINE #include <stdlib.h> NEW_LINE void findRoots ( int a , int b , int c ) { if ( a == 0 ) { printf ( " Invalid " ) ; return ; } int d = b * b - 4 * a * c ; double sqrt_val = sqrt ( abs ( d ) ) ; if ( d > 0 ) { printf ( " Roots ▁ are ▁ real ▁ and ▁ different ▁ STRNEWLINE " ) ; printf ( " % f % f " , ( double ) ( - b + sqrt_val ) / ( 2 * a ) , ( double ) ( - b - sqrt_val ) / ( 2 * a ) ) ; } else if ( d == 0 ) { printf ( " Roots ▁ are ▁ real ▁ and ▁ same ▁ STRNEWLINE " ) ; printf ( " % f " , - ( double ) b / ( 2 * a ) ) ; } { printf ( " Roots ▁ are ▁ complex ▁ STRNEWLINE " ) ; printf ( " % f ▁ + ▁ i % f % f - i % f " , - ( double ) b / ( 2 * a ) , sqrt_val / ( 2 * a ) , - ( double ) b / ( 2 * a ) , sqrt_val / ( 2 * a ) ; } } int main ( ) { int a = 1 , b = -7 , c = 12 ; findRoots ( a , b , c ) ; return 0 ; }