| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 574 人关注过本帖
标题:几道考试题,不得其解,望大虾指导
取消只看楼主 加入收藏
said9999
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2011-10-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
几道考试题,不得其解,望大虾指导
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
said9999
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2011-10-7
收藏
得分:0 
回复 2楼 pauljames
就是啊,,,老师要出这种题,,,也得上了
2011-10-07 23:40
快速回复:几道考试题,不得其解,望大虾指导
数据加载中...
 
   



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

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