一、运行结果;
二、源代码;
cs
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <math.h>
//声明函数;
//判断条件等于0时;
void zeor(double a, double b);
//判断条件大于0时;
void bigzeor(double p, double q);
//判断条件小于0时;
void smallzeor();
int main()
{
//初始化变量值;
double a, b, c, p, q, judge;
//获取用户输入数据;
printf("请输入a, b, c的值:");
scanf("%lf %lf %lf", &a, &b, &c);
//运算;
judge = b * b - 4 * a * c;
p = -b / (2.0 * a);
q = sqrt(judge) / (2.0 * a);
//判断;
if (judge >= 0)
{
if (judge = 0)
{
//调用函数;
zeor(a, b);
}
else
{
//调用函数;
bigzeor(p, q);
}
}
else
{
//调用函数;
smallzeor();
}
return 0;
}
//实现zeor函数;
void zeor(double a, double b)
{
//初始换变量值;
double x1 = 0;
double x2 = 0;
//运算;
x1 = x2 = (-2.0 * a) / b;
//输出结果;
printf("函数的根为:x1=x2=%.2f\n", x1);
}
//实现bigzeor函数;
void bigzeor(double p, double q)
{
//初始换变量值;
double x1 = 0;
double x2 = 0;
//运算;
x1 = p + q;
x2 = p - q;
//输出结果;
printf("函数的根为:x1=%.2f, x2=%.2f\n", x1, x2);
}
//实现smallzeor函数;
void smallzeor()
{
//输出结果;
printf("函数无根!\n");
}