Friday 7 November 2014

Write a C++ program illustrating interactive program for computing the roots of a quadratic equation by handing all possible cases use streams to perform I/O operations

#include<iostream.h>
#include<math.h>
int main()
{
float a,b,c,d,root1,root2;
cout<<"Enter value of a, b and c : ";
cin>>a>>b>>c;
d=b*b-4*a*c;
if(d==0)
{
root1=(-b)/(2*a);
root2=root1;
cout<<"Roots are real & equal";
}
else if(d>0)
{
root1=-(b+sqrt(d))/(2*a);
root2=-(b-sqrt(d))/(2*a);
cout<<"Roots are real & distinct";
}
else
{
root1=(-b)/(2*a);
root2=sqrt(-d)/(2*a);
cout<<"Roots are imaginary";
}
cout<<"\nRoot 1= "<<root1<<"\nRoot 2= "<<root2;
getch();
return 0;
}

4 comments:

  1. You’ve made various nice points there. I did specific search terms around the matter and found mainly individuals will believe your site Venito

    ReplyDelete
  2. The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I mean, I do know it was my option to learn, however I really thought youd have one thing interesting to say. All I hear is a bunch of whining about something that you may repair when you werent too busy looking for attention. Leather Watch Bands

    ReplyDelete