早教吧作业答案频道 -->其他-->
菜鸟程序改错#include#includeintmain(void){inta=1;intb=2;intc=1;doubledelta;doublex1;doublex2;intdelta=b*b-4*a*c;if(delta>0){x1=(-b+sqrt(delta)/(2*a);x2=(-b-sqrt(delta)/(2*a);printf("该一元二次方程有
题目详情
菜鸟程序改错
# include
# include
int main(void)
{ int a = 1;
int b = 2;
int c = 1;
double delta;
double x1 ;
double x2 ;
int delta = b*b-4*a*c;
if ( delta > 0 )
{ x1= (-b + sqrt(delta)/(2*a);
x2= (-b - sqrt(delta)/(2*a);
printf ("该一元二次方程有两个解,x1 = %f,x2 = %f\n",x1,x2);
}
else if ( delta == 0 )
\x05{ x1=(-b)/(2*a);
x2 = x1 ;
\x05\x05printf ("该一元二次方程有唯一解,x1 = x2 = %f\n",x1);
\x05\x05
\x05\x05}
else
\x05{ printf ("无解"\n",x1); }
\x05return 0;
}
-------------------Configuration:Cpp2 - Win32 Debug--------------------
Compiling...
Cpp2.cpp
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(12) :error C2371:'delta' :redefinition; different basic types
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(9) :see declaration of 'delta'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(15) :error C2143:syntax error :missing ')' before ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(16) :error C2143:syntax error :missing ')' before ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(26) :error C2017:illegal escape sequence
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(26) :error C2001:newline in constant
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(26) :error C2146:syntax error :missing ')' before identifier 'n'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(30) :fatal error C1004:unexpected end of file found
执行 cl.exe 时出错.
Cpp2.obj - 1 error(s),0 warning(s)
# include
# include
int main(void)
{ int a = 1;
int b = 2;
int c = 1;
double delta;
double x1 ;
double x2 ;
int delta = b*b-4*a*c;
if ( delta > 0 )
{ x1= (-b + sqrt(delta)/(2*a);
x2= (-b - sqrt(delta)/(2*a);
printf ("该一元二次方程有两个解,x1 = %f,x2 = %f\n",x1,x2);
}
else if ( delta == 0 )
\x05{ x1=(-b)/(2*a);
x2 = x1 ;
\x05\x05printf ("该一元二次方程有唯一解,x1 = x2 = %f\n",x1);
\x05\x05
\x05\x05}
else
\x05{ printf ("无解"\n",x1); }
\x05return 0;
}
-------------------Configuration:Cpp2 - Win32 Debug--------------------
Compiling...
Cpp2.cpp
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(12) :error C2371:'delta' :redefinition; different basic types
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(9) :see declaration of 'delta'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(15) :error C2143:syntax error :missing ')' before ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(16) :error C2143:syntax error :missing ')' before ';'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(26) :error C2017:illegal escape sequence
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(26) :error C2001:newline in constant
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(26) :error C2146:syntax error :missing ')' before identifier 'n'
C:\Documents and Settings\Administrator\桌面\新建文件夹\Cpp2.cpp(30) :fatal error C1004:unexpected end of file found
执行 cl.exe 时出错.
Cpp2.obj - 1 error(s),0 warning(s)
▼优质解答
答案和解析
编译的问题这样改就没了.
# include
# include
int main(void)
{ int a = 1;
int b = 2;
int c = 1;
double delta = b*b-4*a*c;
double x1 ;
double x2 ;
// int delta = b*b-4*a*c; // <== delta定义过了
if ( delta > 0 )
{ x1= (-b + sqrt(delta))/(2*a); // <== 原来括号不配对
x2= (-b - sqrt(delta))/(2*a); // <== 原来括号不配对
printf ("该一元二次方程有两个解,x1 = %f, x2 = %f\n",x1, x2);
}
else if ( delta == 0 )
{ x1=(-b)/(2*a);
x2 = x1 ;
printf ("该一元二次方程有唯一解,x1 = x2 = %f\n",x1);
}
else
{ printf ("无解\n",x1); } // <== 原来多一个双引号
return 0;
}
运行结果:
该一元二次方程有唯一解,x1 = x2 = -1.000000
# include
# include
int main(void)
{ int a = 1;
int b = 2;
int c = 1;
double delta = b*b-4*a*c;
double x1 ;
double x2 ;
// int delta = b*b-4*a*c; // <== delta定义过了
if ( delta > 0 )
{ x1= (-b + sqrt(delta))/(2*a); // <== 原来括号不配对
x2= (-b - sqrt(delta))/(2*a); // <== 原来括号不配对
printf ("该一元二次方程有两个解,x1 = %f, x2 = %f\n",x1, x2);
}
else if ( delta == 0 )
{ x1=(-b)/(2*a);
x2 = x1 ;
printf ("该一元二次方程有唯一解,x1 = x2 = %f\n",x1);
}
else
{ printf ("无解\n",x1); } // <== 原来多一个双引号
return 0;
}
运行结果:
该一元二次方程有唯一解,x1 = x2 = -1.000000
看了 菜鸟程序改错#include...的网友还看了以下:
如图4所示,一定质量的理想气体,从状态A经绝热过程A→B,等容过程B→C,等温过程C→A,又回到了 2020-05-14 …
如果x1x2是一元二次方程ax2+bx+c=0的两根如果x1x2是一元二次方程ax2+bx+c=0 2020-05-16 …
已知等腰三角形三边长为A,B,C,A=C,关于X的一元二次方程ax^2-(根号2)bx+c=0的两 2020-06-08 …
1、abcs+scbc=a0bsc,求a、b、c、s代表什么数?须有过程2、第一个方程:a+b+c 2020-07-09 …
关于代数法解一元二次方程的问题代数法(可解全部一元二次方程)ax^2+bx+c=0同时除以a,可变 2020-07-21 …
一些一元二次方程提高题,超急.1.如果(1-m2-n2)(m2+n2)=-6没那么m2+n2=2. 2020-07-31 …
当a,b,c满足什么条件时,方程(a-1)x2-bx+c=0是一元二次方程?这时方程的二次项系数、 2020-08-01 …
初三一元二次方程1.计算题:(x^2+x)(x^2+x-2)=24求过程2.已知一元二次方程x^2 2020-08-02 …
下列说法错误的是()A.x+y2=2x=−2是二元二次方程组B.x4+2=0既是二项方程又是双二次 2020-08-02 …
有一道关于一元二次方程的题目解关于x的方程c+a-2b≠0(c+a-2b)x平方+(a+b-2c)x 2020-12-13 …