填空题 1.  下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数组中共有M个字符串,且串长小于N。
    请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
    注意:部分源程序给出如下。
    不得增行或删行,也不得更改程序的结构!
    试颢程序:
    #include<stdio.h>
    #include<string.h>
    #define M 5
    #define N 20
    int fun(char (* ss)[N], int *n)
    {  int i, k=0, len=N;
    /********found********/
    for(i=0; i<______; i++)
    {  len=strlen (ss[i]);
    if(i==0)  *n=len;
    /********found********/
    if(len ______ *n)
    { *n=len;
    k=i;
    }
    }
    /********found********/
    return(______);
    }
    main()
    {  char  ss[M][N]={"shanghai","guangzhou","beijing","tianjing","chongqing");
    int n,k,i;
    printf ("\nThe original strings are :\n");
    for(i=0;i<M;i ++)puts(ss [i]);
    k=fun(ss,&n);
    printf ("\nThe length of shortest string is : % d\n",n);
    printf ("\nThe shortest string is : % s\n",ss[k]);
    }
  • 1、
【正确答案】 1、(1)M    (2)<    (3)k    
【答案解析】[考点]
   本题考查:for循环语句的循环条件;if语句条件表达式;return语句完成函数值的返回。
   
   填空1:题目指出ss所指字符串数组中共有M个字符串,所以for循环语句的循环条件是i<M。
   填空2:要求求长度最短的字符串,*n中存放的是已知字符串中长度最短的字符串的长度,将当前字符串长度与* n比较,若小于* n,则将该长度值赋给*n,因此if语句的条件表达式为:len<*n。
   填空3:将最短字符串的行下标作为函数值返回,变量k存储行下标的值。