填空题(C语言)

发布时间 : 星期一 文章填空题(C语言)更新完毕开始阅读

填空题(C) 21

float score[3]; }STU;

void show(STU tt) { int i;

printf(\ for(i=0; i<3; i++)

printf(\ printf(\}

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

void modify(___1___ *ss,float a) { int i;

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

/**********found**********/ ss->___2___ *=a; } main( )

{ STU std={ 1,\ float a;

printf(\ show(std);

printf(\/**********found**********/ modify(___3___,a);

printf(\ show(std); }

答案:【1】STU 【2】score[i] 【3】&std

57.给定程序中,函数fun的功能是:将形参指针

所指结构体数组中的三个元素按num成员进行升序排列。

#include typedef struct { int num;

char name[10]; }PERSON;

/**********found**********/ void fun(PERSON ___1___) {

/**********found**********/ ___2___ temp;

if(std[0].num>std[1].num)

{ temp=std[0]; std[0]=std[1]; std[1]=temp; } if(std[0].num>std[2].num)

{ temp=std[0]; std[0]=std[2]; std[2]=temp; } if(std[1].num>std[2].num)

{ temp=std[1]; std[1]=std[2]; std[2]=temp; }

}

main()

{ PERSON std[ ]={ 5,\ int i;

/**********found**********/ fun(___3___);

printf(\ for(i=0; i<3; i++)

printf(\} 答案:【1】std[3] 【2】PERSON 【3】std

58.给定程序中,函数fun的动能是:将形参std昕指结构体数组中年龄最大者的数据作为函数值返回,并在main函数中输出。 #include typedef struct { char name[10]; int age; }STD;

STD fun(STD std[], int n) { STD max; int i;

/**********found**********/ max= ___1___;

for(i=1; i

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

if(max.age<___2___) max=std[i]; return max; }

main( )

{ STD std[5]={\ STD max;

max=fun(std,5);

printf(\/**********found**********/

printf(\}

答案:【1】*std 【2】std[i].age 【3】max.name

59.给定程序中,函数fun的功能是:对形参ss所指字符串数组中的M个字符串按长度由短到长进行排序。ss所指字符串数组中共有M个字符串,且串长 #include #define M 5 #define N 20

void fun(char (*ss)[N])

{ int i, j, k, n[M]; char t[N];

for(i=0; i

填空题(C) 22

for(i=0; i

/**********found**********/ for(j=___1___; j

if(n[k]>n[j]) ___2___; if(k!=i)

{ strcpy(t,ss[i]);

strcpy(ss[i],ss[k]); /**********found**********/

strcpy(ss[k],___3___); n[k]=n[i]; } } }

main()

{ char ss[M][N]={\ int i;

printf(\ for(i=0; i

printf(\

for(i=0; i

60.给定程序中,函数fun的功能是:求出形参ss所指字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中共有M个字符串,且串长 #include #define M 5 #define N 20

void fun(char (*ss)[N])

{ int i, j, k=0, n, m, len; for(i=0; in) {

/**********found**********/ n=len; ___1___=i; } }

for(i=0; i

len=strlen(ss[i]);

/**********found**********/ for(j=___2___; j>=0; j--) ss[i][m--]=ss[i][j]; for(j=0; j

main()

{ char ss[M][N]={\

int i;

printf(\ for(i=0; i

printf(\

for(i=0; i

62.给定程序中,函数fun的功能是:求ss所指字符串数组中长度最长的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指变量中。ss所指字符串数组中共有M个字符串,且串长 #define M 5 #define N 20

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

int fun(char (*ss) ___1___, int *n) { int i, k=0, len=0; for(i=0; i*n) {

/**********found**********/ ___3___; k=i; } }

return(k); }

main()

{ char ss[M][N]={\ int n,k,i;

printf(\ for(i=0;i

printf(\

填空题(C)

printf(\

23

/**********found**********/ t2[j]=s[i]; ___1___; }

else t1[k++]=s[i]; t2[j]=0; t1[k]=0;

/**********found**********/ }

答案:【1】[N] 【2】len 【3】*n=len

63.给定程序中,函数fun的功能是:求ss所指字符

串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指变量中。ss所指字符串数组中共有M个字符串,且串长 #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]={\ int n,k,i;

printf(\ for(i=0;i

printf(\length of shortest string is : %d\\n\

printf(\}

答案:【1】M 【2】< 【3】k

64.给定程序中,函数fun的功能是:将s所指字符串中的所有数字字符移到所有非数字字符之后,并保持数字字符串和非数字字符串原有的先后次序。例如,形参s所指的字符串为:def35adh3kjsdf7。执行结果为:defadhkjsdf3537。

#include void fun(char *s)

{ int i, j=0, k=0; char t1[80], t2[80]; for(i=0; s[i]!='\\0'; i++) if(s[i]>='0' && s[i]<='9') {

for(i=0; i

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

for(i=0; i<___3___; i++) s[k+i]=t2[i]; } main()

{ char s[80]=\

printf(\ fun(s);

printf(\}

答案:【1】j++ 【2】s[i]=t1[i] 【3】j

65.给定程序中,函数fun的功能是:在形参s所指字符串中的每个数字字符之后插入一个*号。例如,形参s所指的字符串为;def35adh3kjsdf7。执行结果为:def3*5*adh3*kjsdf7*。 #include void fun(char *s) { int i, j, n;

for(i=0; s[i]!='\\0'; i++) /**********found**********/

if(s[i]>='0' ___1___ s[i]<='9') { n=0;

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

while(s[i+1+n]!= ___2___) n++; for(j=i+n+1; j>i; j--) /**********found**********/ s[j+1]= ___3___; s[j+1]='*'; i=i+1;

} }

main()

{ char s[80]=\

printf(\ fun(s);

printf(\}

答案:【1】&& 【2】0 【3】s[j]

66.给定程序中,函数fun的功能是;统计形参s所指字符串中数字字符出现的次数,并存放在形参t所

填空题(C) 24

指的变量中,最后在主函数中输出。例如,形参s所指的字符串为:abcdef35adgh3kjsdf7。输出结呆为;4。 #include

void fun(char *s, int *t) { int i, n; n=0;

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

for(i=0; ___1___ !=NULL; i++) /**********found**********/

if(s[i]>='0'&&s[i]<= ___2___ ) n++; /**********found**********/ ___3___ ; }

main()

{ char s[80]=\ int t;

printf(\

fun(s,&t);

printf(\} 答案:【1】s[i] 【2】'9' 【3】*t=n

67.给定程序中,函数fun的功能是:把形参s所指字符串中下标为奇数的字符右移到下一个奇数位置,最右边被移出字符串的字符绕回放到第一个奇数位置,下标为偶数的字符不动(注:字符串的长度大于等于2)。例如,形参s所指的字符串为:abcdefgh,执行结果为;ahcbedgf。

#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]=\

printf(\ fun(s);

printf(\} 答案:【1】1 【2】s[k] 【3】c 68.给定程序中,函数fun的功能是:对形参s所指字

符串中下标为奇数的字符按ASClI码大小递增排序,并将排序后下标为奇数的字符取出,存入形参p所指字符数组中,形成一个新串。例如,形参s所指的字符串为:baawrskjghzlicda,执行后p所指字符数组中的字符串应为:aachjlsw。

#include

void fun(char *s, char *p) { int i, j, n, x, t; n=0;

for(i=0; s[i]!='\\0'; i++) n++; for(i=1; i

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

for(j=___2___+2 ; js[j]) t=j; if(t!=i)

{ x=s[i]; s[i]=s[t]; s[t]=x; } }

for(i=1,j=0; i

main()

{ char s[80]=\

printf(\ fun(s,p);

printf(\} 答案:【1】t=i 【2】i 【3】0

69.给定程序中,函数fun的功能是:在形参s所指字符串中寻找与参数c相同的字符,并在其后插入一个与之相同的字符,若找不到相同的字符则函数不做任何处理。例如,所指字符串为:baacda,c中的字符为:a,执行后s所指字符串为:baaaacdaa。 #include

void fun(char *s, char c) { int i, j, n;

/**********found**********/ for(i=0; s[i]!=___1___ ; i++) if(s[i]==c) {

/**********found**********/ n=___2___ ;

while(s[i+1+n]!='\\0') n++;

for(j=i+n+1; j>i; j--) s[j+1]=s[j]; /**********found**********/

联系合同范文客服:xxxxx#qq.com(#替换为@)