这个程序是通过输入abc计算一元二次方程组,要求解是复数时重新输入并计算,然后我如果直接输入1 2 1,计算出来就是正确的,但是如果我第一次输入的是解为复数的数字,然后再输入1 2 1,他最后结果就成了-1.#J,但是计算过程都是一样的,请问这是怎么回事
#include<stdio.h>
#include<math.h>
int main()
{
int a, b, c;
printf("input the number of 'a''b''c':");
scanf("%d%d%d", &a, &b, &c);
printf("\n");
if (a > 10 || a < -10 || b>10 || b < -10 || c>10 || c < -10)
{
printf("ERROR!\nreinput the number:");
scanf("%d%d%d", &a, &b, &c);
}
if (a == 0 && b == 0)
{
printf("ERROR!\nreinput the number of 'a''b':");
scanf("%d%d", &a, &b);
if (a == 0)
{
printf("the x is:\n%.2lf", -c * 1.0 / b);
}}
else {
int m = b * b - 4 * a * c;
if (m < 0)
{
printf("ERROR!\nreinput the number of 'a''b''c':");
scanf("%d%d%d", &a, &b,&c);
printf("the x is:%.2lf %.2lf", (-b + sqrt(m)) / 2, (-b - sqrt(m)) / 2);
}
else
{
printf("the x is:%.2lf %.2lf", (-b + sqrt(m)) / 2, (-b - sqrt(m)) / 2);
return 0;
}
}
}
当m<0怎么能对m开平方
if (m < 0)
{
printf("ERROR!\nreinput the number of 'a''b''c':");
scanf("%d%d%d", &a, &b,&c);
printf("the x is:%.2lf %.2lf", (-b + sqrt(m)) / 2, (-b - sqrt(m)) / 2);
}