#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,x1,x2;
cout<<"Enter coefficient of x^2 (a) ";
cin>>a;
cout<<"Enter coefficient of x (b) ";
cin>>b;
cout<<"Enter constant term (c) ";
cin>>c;
d=b*b-(4*a*c);
if (d<0)
{ cout<<"Roots of the equation are imaginary ";
}
if (d==0)
{ x1=((-b)+d)/2;
cout<<"Roots of the equation are real and equal "<<"\n";
cout<<" Roots = "<<x1;
}
if (d>0)
{ x1=((-b)+d)/2;
x2=((-b)-d)/2;
cout<<"Root 1 = "<<x1;
cout<<"Root 2 = "<<x2;
}
getch();
}
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,x1,x2;
cout<<"Enter coefficient of x^2 (a) ";
cin>>a;
cout<<"Enter coefficient of x (b) ";
cin>>b;
cout<<"Enter constant term (c) ";
cin>>c;
d=b*b-(4*a*c);
if (d<0)
{ cout<<"Roots of the equation are imaginary ";
}
if (d==0)
{ x1=((-b)+d)/2;
cout<<"Roots of the equation are real and equal "<<"\n";
cout<<" Roots = "<<x1;
}
if (d>0)
{ x1=((-b)+d)/2;
x2=((-b)-d)/2;
cout<<"Root 1 = "<<x1;
cout<<"Root 2 = "<<x2;
}
getch();
}
No comments:
Post a Comment