#include #include #include main() { float a = 1.0,b = 1.0,c = 1.0,disc = 1.0,dino = 1.0; clrscr(); printf("\nThis program will find the roots of quadratic equation given a,b & c"); printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); printf("\nPlease make sure you enter non - zero numbers."); do { printf("\nEnter a,b and c:"); scanf("%f %f %f",&a,&b,&c); if(a*b*c==0) printf("\nThe program accepts only non-zero numbers"); } while(a*b*c == 0); disc = b*b-4.*a*c; dino = 2.0*a; if(disc == 0) { printf("\nRoots are real and equal"); printf("\nRoot 1 = %.2f\nRoot 2 = %.2f",-(b/dino),-(b/dino)); } else if(disc > 0) { printf("\nRoots are real and distinct"); printf("\nRoot 1 = %.2f\nRoot 2 = %.2f",-b/dino+sqrt(disc)/dino,-b/dino-sqrt(disc)/dino); } else { printf("\nRoots are complex"); printf("\nRoot 1 = %.2f + i %.2f\nRoot 2 = %.2f - i %.2f",-b/dino,sqrt(abs(disc))/dino,-b/dino,sqrt(abs(disc))/dino); } getch(); }