37、給定程序中,函數(shù)fun的功能是:把形參s所指字符串中下標為奇數(shù)的字符右移到下一個奇數(shù)位置,最右邊被移出字符串的字符繞回放到第一個奇數(shù)位置,下標為偶數(shù)的字符不動(注:字符串的長度大于等于2)。例如,形參s所指的字符串為:abcdefgh,執(zhí)行結(jié)果為:ahcbedgf。
請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。
注意:源程序存放在考生文件夾下的BLANK1.C中。
不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
#include
void fun(char *s)
{ int i, n, k; char c;
n=0;
for(i=0; s[i]!='\0'; i++) n++;
/**********found**********/
if(n%2==0) k=n-___1___ ;
else k=n-2;
/**********found**********/
c=___2___ ;
for(i=k-2; i>=1; i=i-2) s[i+2]=s[i];
/**********found**********/
s[1]=___3___ ;
}
main()
{ char s[80]="abcdefgh";
printf("\nThe original string is : %s\n",s);
fun(s);
printf("\nThe result is : %s\n",s);
}
38、給定程序中,函數(shù)fun的功能是:求ss所指字符串數(shù)組中長度最短的字符串所在的行下標,作為函數(shù)值返回,并把其串長放在形參n所指變量中。ss所指字符串數(shù)組****有M個字符串,且串長
請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。
注意:源程序存放在考生文件夾下的BLANK1.C中。
不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
#include
#include
#define M 5
#define N 20
int fun(char (*ss)[N], int *n)
{ int i, k=0, len= N;
/**********found**********/
for(i=0; i<___1___; i++)
{ len=strlen(ss[i]);
if(i==0) *n=len;
/**********found**********/
if(len ___2___ *n)
{ *n=len;
k=i;
}
}
/**********found**********/
return(___3___);
}
main()
{ char ss[M][N]={"shanghai","guangzhou","beijing","tianjing","chongqing"};
int n,k,i;
printf("\nThe original strings are :\n");
for(i=0;i
k=fun(ss,&n);
printf("\nThe length of shortest string is : %d\n",n);
printf("\nThe shortest string is : %s\n",ss[k]);
}