口袋社区-Poke The BBS's Archiver

深红喷火龙 发表于 2008-6-30 16:26

问下……

[font=宋体]别问我这段东西那里不明白,整段都不明白…………[/font]
[font=Times New Roman] [/font]
[font=宋体]如果输入这样子:[/font][font=Times New Roman]2+4*2/3+4\n[/font]
[font=宋体]输出[/font][font=Times New Roman]2+4*2/3+4=8.00\n[/font][font=宋体](大概这里的运算法则加法和乘除法优先级一样)[/font]
[font=宋体](先写出输出结果,[/font][font=Times New Roman] [/font][font=宋体]后边说明我哪里不明白比较方便一些。)[/font]
[font=Times New Roman]#include"stdio.h"[/font]
[font=Times New Roman]int main(void)[/font]
[font=Times New Roman]{[/font]
[font=Times New Roman]
double x,y;[/font]
[font=Times New Roman]
char c;[/font]
[font=Times New Roman]loop1:[/font]
[font=Times New Roman]
printf("input expression");[/font]
[font=Times New Roman]
scanf("%lf",&x);[/font]
[font=Times New Roman]
printf("%.0f",x);[/font]
[font=Times New Roman]
while((c=getchar())!='\n')[/font]
[font=Times New Roman]
{/*[/font][font=宋体]这里开始有疑问了[/font][font=Times New Roman]*/[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]loop2:[/font]
[font=Times New Roman]
printf("%c",c);[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]
scanf("%lf",&y);[/font]
[font=Times New Roman]
printf("%.0f",y);[/font]
[font=Times New Roman]/*[/font][font=宋体]第一个问题:如果输入“[/font][font=Times New Roman]2+3+[/font][font=Times New Roman]4[/font][font=宋体]”[/font][font=宋体],[/font][font=Times New Roman]while[/font][font=宋体]之前那一段把[/font][font=Times New Roman]2[/font][font=宋体]赋予给[/font][font=Times New Roman]x[/font][font=宋体]了,然后[/font][font=Times New Roman]while[/font][font=宋体]一行中那[/font][font=Times New Roman]getchar[/font][font=宋体]()把‘[/font][font=Times New Roman]+[/font][font=宋体]’赋予[/font][font=Times New Roman]c[/font][font=宋体],额,大概有个读入焦点(用词不知准确否)的东西,焦点就移到‘[/font][font=Times New Roman]+[/font][font=宋体]’之后,[/font][font=Times New Roman]scanf[/font][font=宋体]就把[/font][font=Times New Roman]3[/font][font=宋体]赋予给[/font][font=Times New Roman]y[/font][font=宋体]。这个读入焦点之类的我假设的,不知有没有,如果没有,就不明白了……请达人证实一下有无这东东[/font][font=Times New Roman]*/[/font]
[font=Times New Roman]
switch(c)[/font]
[font=Times New Roman]
{[/font]
[font=Times New Roman]
case '+':[/font]
[font=Times New Roman]
x=x+y;[/font]
[font=Times New Roman]
break;[/font]
[font=Times New Roman]
case '-':[/font]
[font=Times New Roman]
x=x-y;[/font]
[font=Times New Roman]
break;[/font]
[font=Times New Roman]
case '*':[/font]
[font=Times New Roman]
x=x*y;[/font]
[font=Times New Roman]
break;[/font]
[font=Times New Roman]
case '/':[/font]
[font=Times New Roman]
if(y!=0)[/font]
[font=Times New Roman]
x=x/y;[/font]
[font=Times New Roman]
else[/font]
[font=Times New Roman]
{[/font]
[font=Times New Roman]
printf("input error,input again\n");[/font]
[font=Times New Roman]
goto loop2;[/font]
[font=Times New Roman]/*[/font][font=宋体]这里这里,所以说很讨厌[/font][font=Times New Roman]goto[/font][font=宋体],无条件退出。如果输入[/font][font=Times New Roman]2/0+4[/font][font=宋体],[/font]
[font=宋体]输出:[/font][font=Times New Roman]input error[/font][font=宋体],[/font][font=Times New Roman]input again\n[/font]
[font=Times New Roman]

/[/font][font=宋体](这里继续输入)[/font]
[font=Times New Roman]       [/font][font=宋体]假如再输入[/font][font=Times New Roman]2[/font][font=宋体],那[/font][font=Times New Roman]+4[/font][font=宋体]后边那一部分是继续执行,还是只算了[/font][font=Times New Roman]2/2[/font][font=宋体]就完了……再帮我一下吧……[/font][font=Times New Roman]*/[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]
[/font]
[font=Times New Roman]
}[/font]
[font=Times New Roman]
break;[/font]
[font=Times New Roman]
default:[/font]
[font=Times New Roman]
printf("input error,input again\n");[/font]
[font=Times New Roman]
goto loop1;[/font]
[font=Times New Roman]
}[/font]
[font=Times New Roman]
}[/font]
[font=Times New Roman]
printf("=%.2f\n",x);[/font]
[font=Times New Roman]}[/font]
[font=Times New Roman] [/font]
[font=宋体]总之很不明白,达人帮忙解答下……[/font]

最美我中文 发表于 2008-6-30 17:52

用调试器一步一步的走走看不就知道了

深红喷火龙 发表于 2008-6-30 19:00

调过了……第二个懒得弄……第一个ms我的猜想是对的,发来证实一下……

最美我中文 发表于 2008-6-30 19:06

C确实不懂


某人也确实不编写这种实用性不很强的东西

据说小火这两天在研究C

深红喷火龙 发表于 2008-6-30 22:20

转移话题无罪……









楼上的头像太惊人了,使自己画的么……水平……—个字,高~

ps:那就有请火sama……

[[i] 本帖最后由 深红喷火龙 于 2008-6-30 22:23 编辑 [/i]]

最美我中文 发表于 2008-7-1 08:03

[quote]原帖由 [i]深红喷火龙[/i] 于 2008-6-30 22:20 发表 [url=http://poketb.com/bbs/redirect.php?goto=findpost&pid=65491&ptid=4722][img]http://poketb.com/bbs/images/common/back.gif[/img][/url]
转移话题无罪……








楼上的头像太惊人了,使自己画的么……水平……—个字,高~

ps:那就有请火sama…… [/quote]



头像是Sata在某人过生日时候的贺礼……被缩小了,签名看不到……

页: [1]

Powered by Discuz! Archiver 6.1.0F  © 2001-2007 Comsenz Inc.