Recent

Comments

Follow us on Facebook

Monday 1 January 2018

Take three values from the user and find discriminant then find the root if disc is greater than less than or equal to zero

Take three values from the user and find discriminant then find the root if disc is greater than less
                                                       than or equal to zero

      #include <iostream>
#include <cmath>
using namespace std;

int main() {

    float a,b,c,R1,R2,disc,realPart,imgPart;
    cout<<"Enter value for a:";
    cin>>a;
    cout<<"Enter value for b:";
    cin>>b;
    cout<<"Enter value for c:";
    cin>>c;
 
 
    disc=b*b-4*a*c;
 
    if(disc>0)
{
        R1=(-b+sqrt(disc))/(2*a);
        R2=(-b-sqrt(disc))/(2*a);
        cout<<"Roots are real and different because discriminant is greater then zero '0'."<<endl;
        cout<<"R1 ="<<R1<<endl;
        cout<<"R2 ="<<R2<<endl;
    }
 
    else if(disc==0)
{
        cout<<"Roots are real and same because disciminant is equal to zero '0'."<<endl;
        R1=(-b/(2*a));
        cout<<"R1 = R2 ="<<R1<<endl;
    }

    else
{
        realPart=-b/(2*a);
        imgPart=sqrt(-disc)/(2*a);
        cout<<"Roots are complex and different because discriminant is less then zero '0'."<<endl;
        cout<<"R1 ="<<realPart<<"+"<<imgPart<<"i"<<endl;
        cout<<"R2 ="<<realPart<<"-"<<imgPart<<"i"<<endl;
    }

    return 0;
}

0 on: "Take three values from the user and find discriminant then find the root if disc is greater than less than or equal to zero"

Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix.

Write a program, that takes 16-Elements in Two-Dimensional-Array that has 4 rows & 4 columns, then display the diagonal of Matrix. ...

propeller ads

PropellerAds