首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 计算机考试 > 等级考试 > 二级考试 >

3月份计算机二级C语言上机练习题及答案(3)

2013-03-30 

  第一题:填空题 请补充fun函数的功能是在字符串的最前端加入n个*号,形成新串,并且覆盖。

  注意:字符串长度最长允许为79。

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

  #include

  #include

  #include

  void fun(char s[], int n)

  {

  char a[80], *p;

  int i;

  p = ___1___;

  for (i=0; i

  a[i] = '*';

  do

  {

  a[i] = ___2___;

  i++;

  } while (___3___);

  a[i] = 0;

  strcpy(s, a);

  }

  main()

  {

  int n;

  char s[80];

  printf("\nEnter a string:");

  gets(s);

  printf("\nThe string\"%s\"\n", s);

  printf("\nEnter n(number of*):");

  scanf("%d", &n);

  fun(s, n);

  printf("\nThe string after insert:\"%s\"\n", s);

  }

  参考答案:

  填空题:第1处填空:s

  第2处填空:*p++

  第3处填空:*(p) 或*p 或者 *p!=0

  第二题:改错题 下列给定程序中函数fun的功能是:先将在字符串中s中的字符按逆顺序存放到t串中,然后把s中的字符按正序连接到t串的后面。例如:s中的字符串为ABCDE时,则t中的字符串应为EDCBAABCDE.

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

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

  #include

  #include

  #include

  void fun(char *s, char *t)

  {

  int s1, i;

  s1 = strlen(s);

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

  for (i=0; i

  t[i] = s[s1-i];

  for (i=0; i

  t[s1+i] = s[i];

  t[2*s1] = '\0';

  }

  main()

  {

  char s[100], t[100];

  printf("\nPlease enter string s:");

  scanf("%s", s);

  fun(s, t);

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

  }

  参考答案:

  改错题:第1处:t[i]=s[s1-i];应改为t[i]=s[s1-i-1];或 t[i]=s[s1-1-i];

  第三题:编程题 已知学生的记录由学号的学习成绩构成,N名学生的数据已存入a结构体数组中。评估编写函数fun,该函数的功能是:找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)。已给出函数的首部,评估完成该函数。

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

  #include

  #include

  #include

  #define N 10

  typedef struct ss

  {

  char num[10];

  int s;

  } STU;

  void fun( STU a[], STU *s )

  {

  }

  main ( )

  {

  STU a[N]={ {"A01",81},{"A02",89},{"A03",66},{"A04",87},{"A05",77},

  {"A06",90},{"A07",79},{"A08",61},{"A09",80},{"A10",71} }, m ;

  int i;

  FILE *out;

  printf("***** The original data *****\n");

  for ( i=0; i

  printf("N0=%s Mark=%d\n", a[i].num,a[i].s);

  fun ( a, &m);

  printf("***** THE RESULT*****\n");

  printf("The top : %s , %d\n", m.num, m.s);

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

  fprintf(out, "%s\n%d", m.num, m.s);

  fclose (out );

  }

  参考答案:

  编程题:

  void fun(int m, int *k, int xx[])

  {

  int I, max;

  max=a[0], s;

  for(i=0; i

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

  {

  max=a[i], s;

  *s=a[i];

  }

  }

更多关注:

3月份计算机一级考试微机知识预测整理汇总

2013年计算机等级考试一级微机考题预测汇总

计算机二级C语言上机题考前预测汇总

更多精彩请关注读书人网计算机频道!


热点排行