标题:几道考试题,不得其解,望大虾指导
只看楼主
said9999
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2011-10-7
结帖率:0
已结贴  问题点数:20 回复次数:3 
几道考试题,不得其解,望大虾指导
1.Given an input file containing a single line of integer values separated by spaces, which of
the following code fragments computes the sum of all the numbers? Assume that the file
pointer in is set up correctly; num and sum are declared as int variables with an initial value
of 0.
(i) while (fscanf(in, "%i", &num) > 0)
sum += num;
(ii) while (fscanf(in, "%i", &num) != 0)
sum += num;
(iii) while (fscanf(in, "%i", &num) >= 0)
sum += num;
(A) None of (i), (ii), (iii).
(B) (i) only.
(C) (ii) only.
(D) (i) and (iii) only.
(E) (ii) and (iii) only.

这道题,我着实没想通返回值的问题,不应该是返回NULL么,,,感觉选1和2但是又没有这个选项,,,

11. The following skeleton code counts the number of uppercase letters in an input string.
char c;
int count = 0;
while ((c = getchar()) != ’\n’)
{
/* Code to count the number of uppercase letters. */
}
As an example, if the input string is:
The quick brown FOX jumps over the lazy DOG.
the value of count is 7. Which of the following are valid statements to count the number of
uppercase letters?
(i) count += isupper(c);
(ii) count += !!isupper(c);
(iii) count += isupper(c) ? 1 : 0;
(iv) count += islower(c) ? 0 : 1;
(A) (i) only.
(B) (iii) only.
(C) (i) and (iii) only.
(D) (ii) and (iii) only.
(E) (iii) and (iv) only.

小弟这道题觉得四个好像都对啊,,,迷茫,,,

Given the following C code fragment (line numbers are indicated):
1: double x, z;
2: int y;
3: scanf("%d %f", &y, &x);
4: z=x+y;
5: printf("x+y=z\n", z);
What do we need to do to fix this code so that it works correctly?
(i) Change line 3 to scanf("%f %d", &y, &x);
(ii) Change line 3 to scanf("%d %lf", &y, &x);
(iii) Change line 2 to double y;
(iv) Change line 4 to z=(x+y);
(v) Change line 5 to printf("x+y=%f", z);
(A) Changes (i) and (iii) are necessary.
(B) Changes (ii), (iii), and (v) are necessary.
(C) Changes (ii) and (v) are necessary.
(D) Changes (iv) and (v) are necessary.
(E) None of the options (A) to (D) are correct.

这题感觉是C,,,但为啥double 用%f 输出呢?
小弟刚学C,,,不才,,,望各位指点一下,,,
搜索更多相关主题的帖子: only single following declared initial 
2011-10-07 18:50
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
得分:10 
你刚学c就找英语题目做,有挑战啊

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2011-10-07 19:50
said9999
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2011-10-7
得分:0 
回复 2楼 pauljames
就是啊,,,老师要出这种题,,,也得上了
2011-10-07 23:40
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
得分:10 
只看明白了1题,fscanf读取失败时返回的是EOF,它应该被定义为-1,所以 i 和 iii 都可以。

My life is brilliant
2011-10-07 23:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-351750-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.842430 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved