C program to Find all Roots of a Quadratic equation
C program to Find all Roots of a Quadratic equation
#include<stdio.h> #include<conio.h> #include<math.h> void main() { float a,b,c,d,r1,r2; printf("Enter the values of a,b & c\n"); scanf("%f%f%f",&a,&b,&c); d=b*b-(4*a*c); if(d>0) { r1=(-b+sqrt(d))/(2*a); r2=(-b-sqrt(d))/(2*a); printf("Roots are real and distinct:\n%f\n%f",r1,r2); } else if(d==0) { r1=-b/(2*a); printf("Roots are real and equal:\n%f",r1); } else { printf("The roots are imaginary"); } getch(); }