while(scanf("%d",&n)==1)

怎么判断执行过程??
关键是 这个语句判断的读入一个整数 如果是非整数 则不执行 所以不明白 是怎么个执行过程

while(scanf("%d",&n)==1)是解释:
scanf的返回值
scanf的返回值由后面的参数决定 scanf("%d%d", &a, &b); 如果a和b都被成功读入,那么scanf的返回值就是2 如果只有a被成功读入,返回值为1 如果a和b都未被成功读入,返回值为0 如果遇到错误或遇到end of file,返回值为EOF。 且返回值为int型.
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-08
scanf的返回值为读入的数据个数,while(scanf("%d",&n)==1)在成功读入1个数据时执行循环体。本回答被提问者和网友采纳
第2个回答  2010-03-26
scanf()函数的返回值就是成功读取的变量个数.

这个循环就是在scanf()读取成功的情况下(也就是读取的内容能够转换成int类型值)执行,如果读取了一个值,但是这个值无法成功的转换成int类型的值(例如输入了一个非数字的字符串),那么这里的scanf()将返回0,此时便退出循环.
第3个回答  2010-03-29
当输入的值为1的时候执行循环
不能输入非整数,因为你用的是 %d 这是整型输入.
要输入浮点型的就得用 %f
第4个回答  2010-03-26
man scanf 里面的帮助

RETURN VALUE
These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.

The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set indicate the error.

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网