
c++做,从键盘上输入a,b,c,计算并输出一元二次方程:ax2+bx+c=0的解。
展开全部
#include<iostream.h>
#include<math.h>
void main()
{
double a,b,c,m,x1,x2;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
m=b*b-4*a*c;
if(m>=0)
{ x1=(-b-sqrt(m))/2;
x2=(-b+sqrt(m))/2;
cout<<"x1="<<x1<<endl;
cout<<"x2="<<x2<<endl; }
else
cout<<"无解"<<endl;
}
#include<math.h>
void main()
{
double a,b,c,m,x1,x2;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
m=b*b-4*a*c;
if(m>=0)
{ x1=(-b-sqrt(m))/2;
x2=(-b+sqrt(m))/2;
cout<<"x1="<<x1<<endl;
cout<<"x2="<<x2<<endl; }
else
cout<<"无解"<<endl;
}
展开全部
void main()
{
int xx;
int a,b,c;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
xx=b*b-4*a*c;
if (xx>0)
{
cout<<"x1="<<(-b+sqrt(xx))/2.0<<endl;
cout<<"x2="<<(-b-sqrt(xx))/2.0<<endl;
}
else if (xx<0)
{
cout<<"x1="<<-b/2.0<<"+"<<sqrt(-xx)/2.0<<"i"<<endl;
cout<<"x2="<<-b/2.0<<"-"<<sqrt(-xx)/2.0<<"i"<<endl;
}
else
{
cout<<"x1=x2="<<-b/2.0<<endl;
}
}
{
int xx;
int a,b,c;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
xx=b*b-4*a*c;
if (xx>0)
{
cout<<"x1="<<(-b+sqrt(xx))/2.0<<endl;
cout<<"x2="<<(-b-sqrt(xx))/2.0<<endl;
}
else if (xx<0)
{
cout<<"x1="<<-b/2.0<<"+"<<sqrt(-xx)/2.0<<"i"<<endl;
cout<<"x2="<<-b/2.0<<"-"<<sqrt(-xx)/2.0<<"i"<<endl;
}
else
{
cout<<"x1=x2="<<-b/2.0<<endl;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <iostream.h>
#include <math.h>
void main()
{
double a,b,c;
cout<<"Please enter a number:";
cin>>a;
cout<<"Please enter b number:";
cin>>b;
cout<<"Please enter c number:";
cin>>c;
if ((b*b-4*a*c)>0)
{
cout<<"x1="<<(-b+sqrt((b*b-4*a*c))/(2*a))<<endl;
cout<<"x2="<<(-b-sqrt((b*b-4*a*c))/(2*a))<<endl;
}
else
cout<<"number error!"<<endl;
}
}
#include <iostream.h>
#include <math.h>
void main()
{
double a,b,c;
cout<<"Please enter a number:";
cin>>a;
cout<<"Please enter b number:";
cin>>b;
cout<<"Please enter c number:";
cin>>c;
if ((b*b-4*a*c)>0)
{
cout<<"x1="<<(-b+sqrt((b*b-4*a*c))/(2*a))<<endl;
cout<<"x2="<<(-b-sqrt((b*b-4*a*c))/(2*a))<<endl;
}
else
cout<<"number error!"<<endl;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream.h>
#include<math.h>
void
main()
{
double
a,b,c,m,x1,x2;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
m=b*b-4*a*c;
if(m>=0)
{
x1=(-b-sqrt(m))/2;
x2=(-b+sqrt(m))/2;
cout<<"x1="<<x1<<endl;
cout<<"x2="<<x2<<endl;
}
else
cout<<"无解"<<endl;
}
#include<math.h>
void
main()
{
double
a,b,c,m,x1,x2;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
m=b*b-4*a*c;
if(m>=0)
{
x1=(-b-sqrt(m))/2;
x2=(-b+sqrt(m))/2;
cout<<"x1="<<x1<<endl;
cout<<"x2="<<x2<<endl;
}
else
cout<<"无解"<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询