错误在哪里?
我是C编程学生。
我的程序在这里有一条错误消息非法的其他没有匹配,如果我无法弄清楚什么是不匹配的。
有人可以帮忙。哪里出错?
谢谢
Khoon
/ *二次方程的根。
12.10.05 * /
#include< stdio.h>
#include< math.h>
int main(无效)
{
int a; int b; int c; float x1; float x2;漂浮E;漂浮R;浮动I;
printf(请键入常量a,b和c的值以找到二次方根);
printf(" equation ax %c + bx + c = 0:,253);
scanf("%d%d%d,& a,& b,& c);
E =(b * b - 4 * a * c);
if(E> 0)
x1 =(-b + sqrt(E))/(2 * a);
x2 =( - b-sqrt(E))/(2 * a);
printf(你的二次方程有两个截然不同的实根:x1 =%1.6f,x2 =%1.6f,x1,x2);
else if(E = 0)
x1 =( - b + sqrt(E))/(2 * a);
x2 =(-b-sqrt(E))/(2 * a);
printf("你的二次方程有两个相同的根:x1 = x2 =%1.6f", x1);
其他
R =(-b / 2 * a);
I =(sqrt(E) )/(2 * a);
printf(你的二次方程有两个不同的假想根:\ n);
printf(" ; x1 =%1.6f +%1.6fi,x2 =%1.6f-%1.6fi \ n,R,I,R,I);
返回0;
}
I am C programming student.
My program here has an error message " illegal else without matching if " which I cannot figure out what is not matching.
Can somebody please help. Where is the mistake?
Thanks
Khoon
/* Roots of a Quadratic Equation.
12.10.05 */
#include <stdio.h>
#include <math.h>
int main (void)
{
int a; int b; int c; float x1; float x2; float E; float R; float I;
printf ("Please key in the value of constant a,b and c for finding the roots of quadratic");
printf ("equation ax%c+bx+c=0 :",253);
scanf ("%d%d%d", &a,&b,&c);
E =(b*b - 4*a*c);
if ( E > 0)
x1 = (-b+sqrt(E))/(2*a);
x2 = (-b-sqrt(E))/(2*a);
printf ("Your quadratic equation has two distinct real roots: x1=%1.6f ,x2=%1.6f",x1,x2);
else if (E = 0)
x1 = (-b+sqrt(E))/(2*a);
x2 = (-b-sqrt(E))/(2*a);
printf ("Your quadratic equation has two same roots : x1=x2=%1.6f",x1);
else
R = (-b/2*a);
I = (sqrt(E))/(2*a);
printf ("Your quadratic equation has two distinct imaginary roots :\n");
printf (" x1=%1.6f+%1.6fi , x2=%1.6f-%1.6fi\n",R,I,R,I);
return 0;
}
在文章< 43 ********** @ news.tm.net.my>,
Red Dragon< ts ***** @ streamyx.com>写道:
In article <43**********@news.tm.net.my>,
Red Dragon <ts*****@streamyx.com> wrote:
if(E> 0)
x1 =( - b + sqrt(E))/(2 * a);
x2 =( - b-sqrt(E))/(2 * a);
if ( E > 0)
x1 = (-b+sqrt(E))/(2*a);
x2 = (-b-sqrt(E))/(2*a);
您似乎依赖于标识来指定结构。
(在Python真正做到这一点之前,这一直被认为是一个笑话。)
你需要围绕当时和其他部分的大括号。
- Richard
You seem to be relying on identation to specify the structure.
(This was long considered a joke until Python actually did it.)
You need braces around the then and else parts.
-- Richard
Red Dragon写道:
Red Dragon wrote:
我是C编程学生。
我的程序在这里有错误信息"非法的其他没有匹配,如果我无法弄清楚什么是不匹配的。
有人可以帮忙。哪里出错?
谢谢
Khoon
/ *二次方程的根。
12.10.05 * /
#include < stdio.h>
#include< math.h>
int main(void)
{
int a; int b; int c; float x1; float x2;漂浮E;漂浮R;浮动I;
printf(请键入常数a,b和c的值以找到二次方根);
printf(方程ax%c + bx + c = 0 :",253);
scanf("%d%d%d"& a,& b,& c);
E =(b * b - 4 * a * c);
if(E> 0)
x1 =( - b + sqrt(E))/(2 * a);
x2 =( - b-sqrt(E))/(2 * a);
I am C programming student.
My program here has an error message " illegal else without matching if " which I cannot figure out what is not matching.
Can somebody please help. Where is the mistake?
Thanks
Khoon
/* Roots of a Quadratic Equation.
12.10.05 */
#include <stdio.h>
#include <math.h>
int main (void)
{
int a; int b; int c; float x1; float x2; float E; float R; float I;
printf ("Please key in the value of constant a,b and c for finding the roots of quadratic");
printf ("equation ax%c+bx+c=0 :",253);
scanf ("%d%d%d", &a,&b,&c);
E =(b*b - 4*a*c);
if ( E > 0)
x1 = (-b+sqrt(E))/(2*a);
x2 = (-b-sqrt(E))/(2*a);
超过1个语句,你需要一个大括号。多数民众赞成为什么我实际上是为了给我的if-else结构提供一个支持,而不仅仅是我支持
的状态。
[抓住程序的其余部分]
More than 1 statement and you need a curly brace. Thats why I actually
try and have a brace ir-respective of the number of statemnts I am
going to put in my if-else contruct.
[snip rest of the program]
Red Dragon ha scritto:
Red Dragon ha scritto:
我是C编程学生。
我的程序在这里有一条错误消息非法的其他没有匹配,如果我无法弄清楚什么是不匹配的。
有人可以帮忙。哪里出错?
谢谢
Khoon
/ *二次方程的根。
12.10.05 * /
#include < stdio.h>
#include< math.h>
int main(void)
{
int a; int b; int c; float x1; float x2;漂浮E;漂浮R;浮动I;
printf(请键入常数a,b和c的值以找到二次方根);
printf(方程ax%c + bx + c = 0 :",253);
scanf("%d%d%d"& a,& b,& c);
E =(b * b - 4 * a * c);
if(E> 0)
x1 =( - b + sqrt(E))/(2 * a);
x2 =( - b-sqrt(E))/(2 * a);
printf("你的二次方程有两个截然不同的实根:x1 =%1.6f,x2 = %1.6f",x1,x2);
else if(E = 0)
x1 =( - b + sqrt(E))/(2 * a) ;
x2 =(-b-sqrt(E))/(2 * a);
printf("你的二次方程有两个相同的根:x1 = x2 =%1.6f" ;,x1);
其他
R =( - b / 2 * a);
I =(sqrt(E))/(2 * a);
printf("你的二次方程有两个不同的虚根:\ n");
printf(" x1 =%1.6f +%1.6fi,x2 =%1.6f-%1.6 fi\\\
及现状t;,R,I,R,I);
返回0;
}
I am C programming student.
My program here has an error message " illegal else without matching if " which I cannot figure out what is not matching.
Can somebody please help. Where is the mistake?
Thanks
Khoon
/* Roots of a Quadratic Equation.
12.10.05 */
#include <stdio.h>
#include <math.h>
int main (void)
{
int a; int b; int c; float x1; float x2; float E; float R; float I;
printf ("Please key in the value of constant a,b and c for finding the roots of quadratic");
printf ("equation ax%c+bx+c=0 :",253);
scanf ("%d%d%d", &a,&b,&c);
E =(b*b - 4*a*c);
if ( E > 0)
x1 = (-b+sqrt(E))/(2*a);
x2 = (-b-sqrt(E))/(2*a);
printf ("Your quadratic equation has two distinct real roots: x1=%1.6f ,x2=%1.6f",x1,x2);
else if (E = 0)
x1 = (-b+sqrt(E))/(2*a);
x2 = (-b-sqrt(E))/(2*a);
printf ("Your quadratic equation has two same roots : x1=x2=%1.6f",x1);
else
R = (-b/2*a);
I = (sqrt(E))/(2*a);
printf ("Your quadratic equation has two distinct imaginary roots :\n");
printf (" x1=%1.6f+%1.6fi , x2=%1.6f-%1.6fi\n",R,I,R,I);
return 0;
}
你需要使用if..else,do..while,while,for,声明一个
结构或函数,以及在逻辑上包含一些
代码的地方。
if(x == 5)
{
/ *做点什么* /
}
while(x!= 10)
{
/ *做点什么* /
}
做
{
/ *做点什么* /
}而(x != 20);
for(x = 0; x
{
/ *做点什么* /
}
等等..
无论如何,一本好书应该在第一页解释这一点。 />
-
Devaraja(Xdevaraja87 ^ gmail ^ c0mX)
Linux注册用户#338167
http://counter.li.org