早教吧作业答案频道 -->其他-->
菜鸟程序改错#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...的网友还看了以下:
Indexexceedsmatrixdimensions.>>disp('');disp(''); 2020-04-26 …
MATLAB解方程问题syms n lanmuda=1.55;n1=1.6375696780514 2020-05-16 …
已知数列{an}的前n项和Sn,若an=1/sqrt(n)+sqrt(n+1),求S10,若 an 2020-05-17 …
有关数列极限的证明方法问题如证明n-->∞时,[sqrt(n^2+a^2)]/n-->1,能否用放 2020-06-05 …
lim(n/(n+1)+n/(n+sqrt(2))+...+n/(n+sqrt(n)))当n->无 2020-06-06 …
纠结,用两种方法算出来的结果不一样题目:lim(n->无穷)[1/sqrt(n^2+1)+1/sq 2020-07-18 …
MATLAB用fsolve解方程H=1.90;lanmuda=1.55;n1=1.55;n2=1. 2020-07-24 …
pascal十分简单的sqrt问题sqrt(n)=sqrt(x)-sqrt(y)求解给出一个正整数 2020-08-02 …
求通项为sqrt(n+2)-2sqrt(n+1)+sqrt(n)的无穷级数的和 2020-11-18 …
一个判断素数的方法:我看到一个最简单的方法用n除以2-sqrt(n),有一个能除尽就不是素数,否则是 2021-02-05 …