Quadratic Equation

Quadratic Equation

#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout<<"HAMMAD AHMAD | BSCE-F17-012| THE UNIVERSITY OF LAHORE, ISLAMABAD CAMPUS\n";
cout<<"Solving Quadratic Equation\n";
int a,b,c,D;
float x,y;
cout<<"Enter the coefficent\n";
cout<<"a: ";
cin>>a;
cout<<"b: ";
cin>>b;
cout<<"c: ";
cin>>c;
D=b*b-4*a*c;
if (D<0) {
cout<<"Both roots are Imaginary\n";
}
if (D==0){
cout<<"Both roots are Equal\n";
x=-b/(2.0*a);
cout<<"The roots are ====> "<<x;
}
if (D>0){
cout<<"Roots are real and distinct\n";
x=(-b+sqrt(D))/(2*a);
y=(-b-sqrt(D))/(2*a);
cout<<"Roots of x are ====> "<<x<<"\n";
cout<<"Roots of y are ====> "<<y<<"\n";
}
return 0;
}

Post a Comment

0 Comments