Here is a C program to find the roots of a quadratic equation.
Quadratic Equation is denoted by
- where "x" is unknown and its value will be the highest degree of the polynomial.
- It can be calculated by knowing the coefficients i.e a , b, c..
- The formula for calculating the is :
-
so now here is a C program fully executed and verified for how to finding the roots of any quadratic equation... - THE PROGRAM IS :
- #include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float a,b,c,d,root1,root2,rpart,ipart;
printf("Enter the values of a,b,and c\n");
scanf("%f%f%f",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d==0)
{
printf("The Roots are equal \n");
root1=-b/(2*a);
root2=root1;
printf("The roots are root1 =%f and root2=%f \n",root1,root2);
}
else if(d>0)
{
printf("The roots are distinct \n");
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
printf("The roots are \n root1 = %f \n and root2 = %f \n",root1,root2);
}
else
{
printf("The roots are imaginary \n");
rpart=(-b/(2*a));
ipart=(sqrt(fabs(d))/(2*a));
printf("The roots are root1 = %f + i%f \n",rpart,ipart);
printf("Root2 = %f-i%f \n",rpart,ipart);
}
getch();
}
Just copy and paste into your Microsoft Visual C++ or Turbo C (these are program developing software)Or else you can try this file and use it to find the roots of a quadratic equation ...
Click HERE to download this file.
~NOTE~ : While executing if you get any warning then just ignore it and continue with your program...
IF FACE ANY PROBLEM DON'T FORGET TO COMMENT ...!!
No comments:
Post a Comment