c语言上机填空改错试题,2013年计算机二级C语言上机试题六十二及答案

2013年计算机二级、一级、三级等更多考试考前培训请进入教育联展网-中国教育培训第一门户,助您顺利通过计算机等级考试!

填空题

请补充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]

2013年计算机二级、一级、三级等更多考试考前培训请进入教育联展网-中国教育培训第一门户,助您顺利通过计算机等级考试!

改错题:

下列给定程序中,函数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<=high/2; j++)

/********found********/

if (high%j == 0)

{

yes = 0;

break

}

if (yes)

{

sum += high;

n++;

}

high--;

}

return sum;

}

main()

{

printf("%d\n", fun(100));

}

答案:break改为break;

2013年计算机二级、一级、三级等更多考试考前培训请进入教育联展网-中国教育培训第一门户,助您顺利通过计算机等级考试!

程序设计:

请编写函数 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 : %d\n\n",num);

out=fopen("out.dat", "w");

for(num=0;num<4;num++)

printf(out, "%d\n", fun(test[num]));

fclose(out);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值