How To write a C program to find the roots of a quadratic equation in C Programming Language ?
Solution:
//To write a C program to find the roots of a quadratic equation #include<stdio.h> #include<math.h> int main() { float a,b,c,x1,x2; printf("Please enter three numbers: \na= \n"); scanf("%f",&a); printf("b= \n"); scanf("%f",&b); printf("c= \n"); scanf("%f",&c); if(b*b-4*a*c < 0) printf("Complex"); else { x1=(-b+sqrt((b*b)-(4*a*c)))/(2*a); x2=(-b-sqrt((b*b)-(4*a*c)))/(2*a); printf("The quadratic roots for the given values of a,b and c are = \nx1=%f \nx2=%f",x1,x2); } return 0; }