Program To Find The Roots of A Quadratic Equation: Bhargav - CH MECH022

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

BHARGAV.

CH MECH022

PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION


#include<stdio.h> #include<conio.h> #include<math.h> main() { int a,b,c,d,r1,r2; float p,q; /*Declaring Variables*/ printf("Enter the quadratic coefficients: "); scanf("%d %d %d",&a,&b,&c); /*Getting Input*/ d=(b*b)-(4*a*c); r1=((-b)+sqrt(d))/(2*a); /*Quadratic formula*/ r2=((-b)-sqrt(d))/(2*a); if(d>0||d=0) /*Test condition*/ { printf("\nThe roots are real and distinct"); printf("\nThe roots of the given quadratic equation are:"); printf("\n%d\n%d",r1,r2); } else { printf("The roots are imaginary"); p=(-b)/(2*a); q=(sqrt(-d)/(2*a)); printf(\nThe roots are %3.2f+i%3.2f and %3.2f-i%3.2f,p,q,p,q); } getch(); }

SAMPLE OUTPUT & INPUT :


Enter the quadratic coefficients: 1 -13 42 The roots are real and distinct The roots of the given quadratic equation are: 7 6

Enter the quadratic coefficients: 1

-4 4 The roots are real and equal The roots of the given quadratic equation are: 2 2 Enter the quadratic coefficients: 1 2 3 The roots are imaginary

You might also like