Created
October 25, 2012 14:19
-
-
Save oott123/3952802 to your computer and use it in GitHub Desktop.
解一元二次方程,可以连续解多次
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "iostream.h" | |
#include "math.h" | |
int main(){ | |
float a,b,c; | |
float x1,x2,deta; | |
bool conti; | |
conti=true; | |
while(conti){ | |
cout<<"ax^2 + bx + c\n"; | |
cout<<"Input a,b,c with Enter between them:\n"; | |
cin>>a;cin>>b;cin>>c; | |
deta=b*b-4*a*c; | |
if (deta==0){ | |
cout<<"Deta is 0!\nAnd x1=x2="; | |
x1=(-b+sqrt(deta))/(2*a); | |
cout<<x1; | |
}else if (deta>0){ | |
cout<<"Deta > 0!\nAnd "; | |
x1=(-b+sqrt(deta))/(2*a); | |
x1=(-b-sqrt(deta))/(2*a); | |
cout<<"x1=";cout<<x1;cout<<",x2=";cout<<x2; | |
}else{ | |
cout<<"Deta < 0!\nAnd "; | |
x1=(-b+sqrt(-deta))/(2*a); | |
x1=(-b-sqrt(-deta))/(2*a); | |
cout<<"x1=";cout<<x1;cout<<",x2=";cout<<x2; | |
} | |
cout<<"\nDo you want to continue? 1 for yes , 0 for no"; | |
cin>>conti; | |
cout<<"\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment