求方程ax~+bx+c=0的根,用3个函数分别求当b~-4ac大于0等于0和小于0时的根并输出结果.从主函数输出abc的值 20
1个回答
展开全部
#include <iostream>
#include <cmath>
using namespace std;
void f(double a,double b, double c) //定义函数要为空类型
{double x1,double x2;
x1=(-b+sqrt(b*b-4*a*c))/(2*a); //注意分母要用括号全部括起来
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
cout<<"x1="<<x1<<" "<<"x2="<<x2<<endl;
}
void k(double a,double b, double c)
{double x;
x=-b/(2*a);
cout<<"x1=x2="<<x<<endl;
}
void m()
{cout<<"error!"<<endl;
}
int main()
{double a,b,c,z;
cout<<"enter a,b,c:";
cin>>a>>b>>c;
z=b*b-4*a*c;
if(z>0)
f(a,b,c);
if(z==0)
k(a,b,c);
if (z<0)
m();}
#include <cmath>
using namespace std;
void f(double a,double b, double c) //定义函数要为空类型
{double x1,double x2;
x1=(-b+sqrt(b*b-4*a*c))/(2*a); //注意分母要用括号全部括起来
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
cout<<"x1="<<x1<<" "<<"x2="<<x2<<endl;
}
void k(double a,double b, double c)
{double x;
x=-b/(2*a);
cout<<"x1=x2="<<x<<endl;
}
void m()
{cout<<"error!"<<endl;
}
int main()
{double a,b,c,z;
cout<<"enter a,b,c:";
cin>>a>>b>>c;
z=b*b-4*a*c;
if(z>0)
f(a,b,c);
if(z==0)
k(a,b,c);
if (z<0)
m();}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询