- 1
- 0
- 约2.05万字
- 约 13页
- 2017-03-03 发布于湖北
- 举报
c编程题汇总讲述
第三章
1.编写一个求方程ax2 + bx + c = 0的根 的程序,用3个函数分别求当b2-4ac大于零、等于零、和小于零时的方程的根。要求从主函数输入a,b,c的值并输出结果。
#include iostream.h
#include math.h
void equation_1 (int a, int b, int c)
{
double x1, x2, temp;
temp = b*b - 4 * a * c;
x1 = (-b + sqrt(temp) ) / (2 * a * 1.0);
x2 = (-b - sqrt(temp) ) / (2 * a * 1.0);
cout两个不相等的实根 endl;
coutx1 = x1, x2 = x2 endl;
}
void equation_2 (int a, int b, int c)
{
double x1, x2, temp;
temp = b*b - 4 * a * c;
x1 = (-b + sqrt(temp) ) / (2 * a * 1.0);
x2 = x1;
cout两个相等的实根 endl;
coutx1 = x1, x2 = x2 endl;
}
void equation_3 (int a, int b, int c)
{
double te
原创力文档

文档评论(0)