模拟试题

3773考试网计算机等级考试模拟试题正文

2014年3月全国计算机二级C语言上机模拟试题四十三之1

来源:2exam.com 2013-10-30 10:16:07

 给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(下标值),未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 

  注意:源程序存放在考生文件夹下的BLANK1.C中。 

  不得增行或删行,也不得更改程序的结构! 

  给定源程序: 

  #include  

  #include  

  #define N 5 

  #define M 8 

  int fun(char (*ss)[M],char *t) 

  { int i; 

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

  if(strcmp(ss[i],t)==0 ) return __2__ ; 

  return -1; 

  } 

  main() 

  { char ch[N][M]={"if","while","switch","int","for"},t[M]; 

  int n,i; 

  printf("\nThe original string\n\n"); 

  for(i=0;i  printf("\nEnter a string for search: "); gets(t); 

  n=fun(ch,t); 

  if(n== __3__) printf("\nDon’t found!\n"); 

  else printf("\nThe position is %d .\n",n); 

  } 

触屏版 电脑版
3773考试网 琼ICP备12003406号-1