Wednesday, 30 August 2017

11D-Prg7 Write a program to read the value of a variable of a quadratic equation and find the discriminant and give the root of the quadratic equation.

// prg7

#include<iostream.h>
#include<math.h>

main()
{
 
    float a,b,c,d,r1,r2;

    cout<<"Enter a b and c \n";
    cin>>a>>b>>c;

    d=b*b-4*a*c;
    if(d==0)
    {
Cout<<"Roots are equal\n";
r1=-b/(2*a);
        r2=r1;
cout<<"R1=R2="<<r1;
    }
    else
    if(d>0)
    {
cout<<"Roots are different\n";
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
        cout<<"Root1="<<r1;
        cout<<"Root2="<<r2;
    }

    else
    cout<<"Complex number \n";

}
    

No comments:

Post a Comment