Find Roots of Quadratic Equation
Here, you will know about the roots of quadratic equation ,and get the example code of c program to find roots of quadratic equation using the bellow equations.
How to find Roots of Quadratic Equation
The roots of a quadratic equation are the values of x which make the equation equal to 0. A quadratic equation has two roots, which are found using the quadratic formula:
x = (-b ± √(b² – 4ac))/2a
where a, b, and c are the coefficients of the equation ax² + bx + c = 0.
ax2+ bx +c = 0
C program to find Roots of Quadratic Equation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | //C program to find Roots of Quadratic Equation #include<conio.h> #include<stdio.h> #include<math.h> int main( ) { int a,b,c,d; float r1,r2,d1; clrscr(); printf("\nEnter Three Constants: "); scanf("%d%d%d",&a,&b,&c); d=((b*b)-(4*a*c)); if(d>0) { printf("\nThe Roots of equation are : "); d1=sqrt(d); r1=(-b+d1)/(2*a); r2=(-b-d1)/(2*a); printf("\nRoot1 = %f\n Root2 = %f",r1,r2); } else if(d==0) { printf("\nThe Roots of equation are Real and Equal"); r1=(-b)/(2*a); printf("\nThe Roots are =Root1=Root2= %f",r1); } else { printf("\nThe Roots of equation are Imaginary"); } getch(); return 0; } |
Input :
Enter Three Constants: 1 2 1
Output :
The Roots of equation are Real And Equal
The Roots are =Root1=Root2= -1.000000
Input :
Enter Three Constants: 2 3 4
Output :
The Roots of equation are Imaginary
Check out our other C programming Examples