help please Do Programming Exercise 4.1 from pages 120- 121 Have your program: D
ID: 3756491 • Letter: H
Question
help please
Explanation / Answer
Writing in C++ (as no language specified)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a,b,c;
float det;
cout<<"Enter values for a,b,c ";
cin>>a>>b>>c;
if(a==0&&b==0&&c==0){
cout<<"Many solutions as all a,b and c are zero ";
}
else if(a==0&&b==0&&c!=0){
cout<<"No solution ";
}else
if(a==0){
cout<<"Not a Quadratic equation";
}else{
det = b*b -4*a*c;
if(det<0){
cout<<"Roots are Complex as det is less then zero ";
}
else if(det==0){
cout<<"Roots are equal and are "<<setprecision(3)<<(float)(-b)/(2*a)<<endl;
}
else
cout<<"Roots are "<<setprecision(3)<<float(-b+det)/(2*a) <<" and "<<setprecision(3)<<float(-b-det)/(2*a);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.