#include<iostream>
#include <math.h>
using namespace std;
int main()
{
double a,b,c,d,x,y;
cout<<"欢迎使用锤子Ethan解方程,一般式为ax^2+bx+c=0"<<endl;
cout<<"请输入系数a,b,c。"<<endl;
cin>>a>>b>>c;
cout<<"你输入的方程是"<<a<<"x^2+"<<b<<"x+"<<c<<"=0"<<endl;
d=b*b-4*a*c;
if(d>=0)
{
if(d>0)
{
x=((-b)+sqrt(d))/(2*a);
y=((-b)-sqrt(d))/(2*a);
cout<<"方程有两个解"<<"\t"<<x<<"\t"<<y<<endl;
}
else
{
x=((-b)+sqrt(d))/(2*a);
cout<<"方程有一个的根:"<<x<<endl;
}
}
else
cout<<"这个方程没有实数解"<<endl;
return 0;
}
本文介绍了一个简单的C++程序,用于解决二次方程 ax^2 + bx + c = 0 的求解过程。通过输入系数a、b、c,程序能够判断方程的解,并输出实数解或提示无实数解。
780

被折叠的 条评论
为什么被折叠?



