编程求一元二次方程ax2+bx+c=0的实数根x1,x2,a,b,c的值由键盘输入
2、编程求一元二次方程ax2+bx+c=0的实数根x1,x2,a,b,c的值由键盘输入,设b2-4ac>0。输入输出参考示例如下:请输入三个系数a,b,c的值:a=1,b...
2、 编程求一元二次方程ax2+bx+c=0的实数根x1,x2,a,b,c的值由键盘输入,设b2-4ac>0。输入输出参考示例如下:
请输入三个系数a,b,c的值:
a=1,b=3,c=2
x1=-1.00
x2=-2.00 展开
请输入三个系数a,b,c的值:
a=1,b=3,c=2
x1=-1.00
x2=-2.00 展开
2个回答
展开全部
C++源程序如下:
#include <iostream>
#include <math.h>
using namespace std;
void main()
{
float a, b, c, x1, x2;
cout << "请输入a, b, c的值:";
cin>> a >> b >> c;
if (b*b - 4*a*c <= 0)
cout << "输入的系数不对,b2-4ac不大于0!程序退出!" << endl;
else
{
x1 = (-b + sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - sqrt(b*b - 4*a*c))/2*a;
cout.precision(2);
cout << "x1 = " << fixed << x1 << endl;
cout << "x2 = " << fixed << x2 << endl;
}
}
C语言源程序如下:
#include <stdio.h>
#include <math.h>
void main()
{
float a, b, c, x1, x2;
printf("请输入a, b, c的值:");
scanf("%f%f%f", &a, &b, &c);
if (b*b - 4*a*c <= 0)
printf("输入的系数不对,b2-4ac不大于0!程序退出!\n");
else
{
x1 = (-b + sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - sqrt(b*b - 4*a*c))/2*a;
printf("x1 = %.2f\n", x1);
printf("x2 = %.2f\n", x2);
}
}
#include <iostream>
#include <math.h>
using namespace std;
void main()
{
float a, b, c, x1, x2;
cout << "请输入a, b, c的值:";
cin>> a >> b >> c;
if (b*b - 4*a*c <= 0)
cout << "输入的系数不对,b2-4ac不大于0!程序退出!" << endl;
else
{
x1 = (-b + sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - sqrt(b*b - 4*a*c))/2*a;
cout.precision(2);
cout << "x1 = " << fixed << x1 << endl;
cout << "x2 = " << fixed << x2 << endl;
}
}
C语言源程序如下:
#include <stdio.h>
#include <math.h>
void main()
{
float a, b, c, x1, x2;
printf("请输入a, b, c的值:");
scanf("%f%f%f", &a, &b, &c);
if (b*b - 4*a*c <= 0)
printf("输入的系数不对,b2-4ac不大于0!程序退出!\n");
else
{
x1 = (-b + sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - sqrt(b*b - 4*a*c))/2*a;
printf("x1 = %.2f\n", x1);
printf("x2 = %.2f\n", x2);
}
}
展开全部
C++源程序如下:
#include
<iostream>
#include
<math.h>
using
namespace
std;
void
main()
{
float
a,
b,
c,
x1,
x2;
cout
<<
"请输入a,
b,
c的值:";
cin>>
a
>>
b
>>
c;
if
(b*b
-
4*a*c
<=
0)
cout
<<
"输入的系数不对,b2-4ac不大于0!程序退出!"
<<
endl;
else
{
x1
=
(-b
+
sqrt(b*b
-
4*a*c))/2*a;
x2
=
(-b
-
sqrt(b*b
-
4*a*c))/2*a;
cout.precision(2);
cout
<<
"x1
=
"
<<
fixed
<<
x1
<<
endl;
cout
<<
"x2
=
"
<<
fixed
<<
x2
<<
endl;
}
}
C语言源程序如下:
#include
<stdio.h>
#include
<math.h>
void
main()
{
float
a,
b,
c,
x1,
x2;
printf("请输入a,
b,
c的值:");
scanf("%f%f%f",
&a,
&b,
&c);
if
(b*b
-
4*a*c
<=
0)
printf("输入的系数不对,b2-4ac不大于0!程序退出!\n");
else
{
x1
=
(-b
+
sqrt(b*b
-
4*a*c))/2*a;
x2
=
(-b
-
sqrt(b*b
-
4*a*c))/2*a;
printf("x1
=
%.2f\n",
x1);
printf("x2
=
%.2f\n",
x2);
}
}
#include
<iostream>
#include
<math.h>
using
namespace
std;
void
main()
{
float
a,
b,
c,
x1,
x2;
cout
<<
"请输入a,
b,
c的值:";
cin>>
a
>>
b
>>
c;
if
(b*b
-
4*a*c
<=
0)
cout
<<
"输入的系数不对,b2-4ac不大于0!程序退出!"
<<
endl;
else
{
x1
=
(-b
+
sqrt(b*b
-
4*a*c))/2*a;
x2
=
(-b
-
sqrt(b*b
-
4*a*c))/2*a;
cout.precision(2);
cout
<<
"x1
=
"
<<
fixed
<<
x1
<<
endl;
cout
<<
"x2
=
"
<<
fixed
<<
x2
<<
endl;
}
}
C语言源程序如下:
#include
<stdio.h>
#include
<math.h>
void
main()
{
float
a,
b,
c,
x1,
x2;
printf("请输入a,
b,
c的值:");
scanf("%f%f%f",
&a,
&b,
&c);
if
(b*b
-
4*a*c
<=
0)
printf("输入的系数不对,b2-4ac不大于0!程序退出!\n");
else
{
x1
=
(-b
+
sqrt(b*b
-
4*a*c))/2*a;
x2
=
(-b
-
sqrt(b*b
-
4*a*c))/2*a;
printf("x1
=
%.2f\n",
x1);
printf("x2
=
%.2f\n",
x2);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询