2013计算机等级考试二级C语言试题及答案14

发布时间:2019-02-04 19:02:01

填空题
请补充main函数,该函数的功能是:从键盘输入一组字符串,以’*’结束输入,并显示出这个字符串。
例如,输入abcdef *, 结果显示abcdef。
仅在横线上添入所编写的若干表达式或语句,勿改动函数中的其他任何内容。
#include
#define N 80
main()
int i = -1, j = 0;
char str[N];
printf("n Input a string n");
do
{
i ;
scanf(_1_);
} while (_2_);
printf("n ******* display the string ******* n");
while (j < i)
{
printf(_3_);
j ;
}
}
答案: (1)“%c”,&str[i]
(2)str[i]!=’*’
(3)”%c”,str[j]

改错题:
下列给定程序中,函数fun的功能是:计算并输出high 以内最大的10个素数之和。 High由主函数传给fun 函数。若high的值为100,则函数的值为732。
#include
#include
#include
int fun(int high)
{
int sum = 0, n = 0, j, yes;
while ((high >= 2) && (n < 10))
{
yes = 1;
for (j=2; j程序设计:
请编写函数 fun,该 函数的功能是:统计一行字符串中单词的个数,作为函数值返回。一行字符串在主函数中输入,规定所有单词由小写字母组成,单词之间由若干个空格隔开,一行的开始和结束都没有空格。
#include
#include
#define N 80
int fun(char *s)
{
}
main()
{
char line[N];
int num=0;
FILE *out;
char *test[] = {"Hello World!", "This is a test string.", "a b", "cde f g,sf l"};
printf("Enter a string :n");
gets(line);
num=fun( line );
printf("The number of word is : %dnn",num);
out=fopen("out.dat", "w");
for(num=0;num
阅读更多其他试题,请访问生活日记网 用日志记录点滴生活!考试试题频道。
喜欢考试试题,那就经常来哦

该内容由生活日记网提供.