精选问答
C程题目,求一元二次方程解.有疑惑..int main(void){ int repeat, ri; double a, b, c, d; scanf("%d", &repeat); for(ri = 1; ri =0) printf("x1 = %0.2f", (-b+sqrt(d))/(2*a)); printf("x2 = %0.2f", (-b-sqrt(d))

2019-05-28

C程题目,求一元二次方程解.有疑惑..
int main(void)
{
int repeat, ri;
double a, b, c, d;
scanf("%d", &repeat);
for(ri = 1; ri =0)
printf("x1 = %0.2f", (-b+sqrt(d))/(2*a));
printf("x2 = %0.2f", (-b-sqrt(d))/(2*a));
else
printf("x1 = %0.2f+%0.2fi", -b/(2*a), sqrt(-d)/(2*a));
printf("x2 = %0.2f-%0.2fi", -b/(2*a), sqrt(-d)/(2*a));
system("pause");
...软件说我else前有语法错误..我检查不出啊...运行的时候也有问题,..会跳出一个"x2=-1.#J"的说-_||..
优质解答
改过之后的程序,粗心的问题啦,少了几个大括号,还有程序尽量做到输入有提示,自己可以加上去.
#include
#include
using namespace std;
int main(void)
{
int repeat,ri;
double a,b,c,d;
scanf("%d",&repeat);
for(ri = 1; ri =0){
printf("x1 = %0.2f",(-b+sqrt(d))/(2*a));
printf("x2 = %0.2f",(-b-sqrt(d))/(2*a));}
else{
printf("x1 = %0.2f+%0.2fi",-b/(2*a),sqrt(-d)/(2*a));
printf("x2 = %0.2f-%0.2fi",-b/(2*a),sqrt(-d)/(2*a)); }
}
system("pause");
}
改过之后的程序,粗心的问题啦,少了几个大括号,还有程序尽量做到输入有提示,自己可以加上去.
#include
#include
using namespace std;
int main(void)
{
int repeat,ri;
double a,b,c,d;
scanf("%d",&repeat);
for(ri = 1; ri =0){
printf("x1 = %0.2f",(-b+sqrt(d))/(2*a));
printf("x2 = %0.2f",(-b-sqrt(d))/(2*a));}
else{
printf("x1 = %0.2f+%0.2fi",-b/(2*a),sqrt(-d)/(2*a));
printf("x2 = %0.2f-%0.2fi",-b/(2*a),sqrt(-d)/(2*a)); }
}
system("pause");
}
相关问答