Sunday, 16 October 2016

HHW Q26. WAP to print roots of a Quadratic equation .

#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();
}

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...