计算机考试A013,2013年计算机二级C语言上机试题三十四及答案

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

填空题

请补充fun函数,该函数的功能是:分类统计一个字符串中元音字母和其它字符的个数(不区分大小写)。

例如,输入aeiouAUpqr,记过为A:2 E:1 I:1 O:1 U:2 other:3

注意:部分源程序给出如下

请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。

试题程序:

#include

#include

#define N 100

void fun(char *str, int bb[])

{

char *p = str;

int i = 0;

for (i=0; i<6; i++)

___1___;

while (*p)

{

switch (*p)

{

case 'A':

case 'a':

bb[0]++;

break;

case 'E':

case 'e':

bb[1]++;

break;

case 'I':

case 'i':

bb[2]++;

break;

case 'O':

case 'o':

bb[3]++;

break;

case 'U':

case 'u':

bb[4]++;

break;

default:

___2___;

}

___3___

}

}

main()

{

char str[N], ss[5] = "AEIOU";

int i;

int bb[6];

printf("Input a string: \n");

gets(str);

printf("the string is: \n");

puts(str);

fun(str, bb);

for (i=0; i<5; i++)

printf("\n%c:%d", ss[i], bb[i]);

printf("\nother:%d", bb[i]);

}

第1处填空:bb[i]=0或*(bb+i)=0

第2处填空:bb[5]++或++bb[5]或bb[5]=bb[5]+1或bb[5]+=1

第3处填空:p++;或++p;或p+=1;或p=p+1;

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

改错题

下列给定程序中,函数fun的功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新数放在t中,高位仍在高位,低位仍在低位,当s中的数为87653142时,t 中的数为7531。

请改正程序中的错误,使其能得出正确结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题 程序:

#include

#include

void fun(long s, long *t)

{

int d;

long s1 = 1;

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

t = 0;

while (s > 0)

{

d = s%10;

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

if (d%2 == 0)

{

*t = d*s1 + *t;

s1 *= 10;

}

s /= 10;

}

}

main()

{

long s, t;

printf("\nPlease enter s: ");

scanf("%ld", &s);

fun(s, &t);

printf("The result is: %ld\n", t);

}

第1处:t =0;应改为*t =0;

第2处:if (d%2 ==0)应改为if(d%2!=0)

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

编程题

学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组S中,请编写函数FUN,它的功能是:把分数最高的学生数据放在H所指的数组中,注意:分数最高的学生可能不只一个,函数返回分数最高的学生的人数。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

#include

#define N 16

typedef struct

{

char num[10];

int s;

} STREC;

int fun ( STREC *a, STREC *b )

{

}

main ()

{

STREC s[N]= {{"GA05",85}, {"GA03",76}, {"GA02",69}, {"GA04",85},

{"GA01",91}, {"GA07",72}, {"GA08",64}, {"GA06", 87},

{"GA015",85}, {"GA013",91}, {"GA012",64}, {"GA014",91},

{"GA011",77}, {"GA017",64}, {"GA018",64}, {"GA016",72}};

STREC h[N];

int i, n;

FILE *out;

n=fun ( s, h );

printf ("The %d highest score :\n", n);

for (i=0; i

printf ("%s %4d\n", h[i]. num, h[i]. s);

printf ("\n");

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

fprintf (out, "%d\n", n);

for (i=0; i

fprintf (out, "%4d\n", h[i].s);

fclose (out );

}

答案是:

int fun(STREC *a,STREC *b)

{

int I,j=0,n=0,max;

max=a[0].s;

for(i=0;i

if(a[i].s>max)

max=a[i].s;

for(i=0;i

if(a[i].s==max)

{

*(b+j)=a[i];

j++;

n++;

}

return n;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值