Saturday 25 May 2013

0 A C - PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION.

Here is a C program to find the roots of a quadratic equation.
Quadratic Equation is denoted by
ax^2+bx+c=0,\,
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 :
x=-\frac{b}{2a}\pm\frac{\sqrt{b^2-4ac\ }}{2a}=\frac{-b\pm\sqrt{b^2-4ac\ }}{2a}.
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 ...!!

Don't Forget to share.... 

Follow on Facebook : Ethical Hacking.

No comments:

Post a Comment