Source Code :    
#include<stdio.h>
#include<math.h>
void main()
{
    float a,b,c,dd,d,x,y;
    clrscr();
    printf("Enter the Values of a,b,c of a Quadratic Equation : ");
    scanf("%f %f %f",&a,&b,&c);
    if(a!=0)
    {
        dd=(b*b)-(4*a*c);
        if(dd<0)
        {
            printf("\n\n\t\tThe Roots are Imaginary");
            dd=-dd;
            d=sqrt(dd);
            x=(-b+d)/(2*a);
            y=(-1)*(-b-d)/(2*a);
            printf("\n\nThe two roots of the Quadratic Equation are :
             x=%5.2f(i) and y=%5.2f(i)",x,y);
        else
        {
             d=sqrt(dd);
             x=(-b+d)/(2*a);  //Calculation of x & y
             y=(-b-d)/(2*a);
             printf("\n\nThe two roots of the Quadratic Equation are : 
                                    x=%5.2f and y=%5.2f",x,y);
        }
    }
    else
    {
      printf("\n\n\t\t The Value of 'a' Cannot be 0. Retry ");
    }
     getch();
}    Output :
Enter the Values of a,b,c of a Quadratic Equation : 6 2 3
            The Roots are Imaginary
The Two Roots of the Quadratic Equation are : x=0.52(i) and y=0.85(i)
 
 
 
No comments:
Post a Comment