好文档 - 专业文书写作范文服务资料分享网站

历年全国计算机等级考试 - 二级C语言上机考试题库及答案

天下 分享 时间: 加入收藏 我要投稿 点赞

} 修改

给定程序MODI。C中函数fun的功能是:求k!(k<13),所求阶乘的值作为函数值返回,例如若(k=10,则应输出:3628800 long fun ( int k) {

/************found************/ if k > 0

return (k*fun(k-1));

/************found************/ else if ( k=0 ) return 1L; } 设计

程序定义了N*N的二维数组。并在主函数中自动赋值,请编写函数fun,函数的功能是:使数组左下三角元素的值乘以n 例如:若n的值为3,a数组的值为

13、B: STU score[i] &std M: ( ) k= =0 P: int i, j; for(i = 0 ; i < N ; i++) for(j = 0 ; j <= i; j++) a[i][j] *= n ; 14.填空

给定程序中,函数fun的功能是:将形参所指结构体数组中的三个元素按num成员进行升序排列

/**********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(\} 修改

给定程序MODI1.c中函数fun的功能是:将m个字符串连接起来组成一个新串,放入pt所指存储区中

int fun ( char str[][10], int m, char *pt ) {

/************found************/ Int k, q, i ;

for ( k = 0; k < m; k++ ) { q = strlen ( str [k] ); for (i=0; i

/************found************/ pt[i] = str[k,i] ; pt += q ; pt[0] = 0 ; } }

设计

程序定义了N*N的二维数组, 并在主函数中自动赋值,请编写函数fun,函数的功能是:使数组左下三角元素中的值全部值0

14、B: *std PERSON std M: int str[k][i] P: int i, j; for(i = 0 ; i < N ; i++) for(j = 0 ; j <= i; j++) a[i][j] =0; 15.填空

给定程序中,函数fun的功能是:将形参std所指结构体数组中年龄最大者的数据作为函数值返回,并在主函数中输出 STD fun(STD std[], int n) { STD max; int i; /**********found**********/ max= ___1___; for(i=1; i

main( )

{ STD std[5]={\ }; STD max; max=fun(std,5);

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

printf(\ Age : %d\\n\} 修改

给定程序MODI1.c中函数fun的功能是:实现两个整数的交换

例如给a和b分别输入60和65,输出为:a=65 b=60 /**********found**********/ void fun ( int a, b ) { int t;

/**********found**********/ t = b; b = a ; a = t; } 设计

请编制一个函数fun,tt指向一个M行N列的二维数组,求二维数组每列中最小元素,并以此放入pp所指一维数组中。二维数组中的数已在主函数中赋予

15、B: *std std[i].age max.name M: int *b t = *b; *b = *a ; *a = t; P: int i,j,

min, k ; for(i = 0 ; i < N ; i++) { min = tt[0][i] ; k = 0 ; for(j = 1 ; j < M ; j++) if(min > tt[j][i]) { min=tt[j][i] ; k = j ; } pp[i] = tt[k][i] ; } 16.填空

程序通过定义并赋初值的方式,利用结构体变量存储了一名学生的信息,函数fun的功能是输出这位学生的信息 /**********found**********/ void show(STU ___1___) { int i;

printf(\ tt.birthday.year, tt.birthday.month, tt.birthday.day); for(i=0; i<3; i++)

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

main( )

{ STU std={ 1,\ printf(\/**********found**********/ show(___3___); }

修改

给定程序MODI1.c中函数fun的功能是:求出数组中最大数和次大数,并把最

大数和a【0】中的数对调,次最大数和a【1】中的书对调 int fun ( int * a, int n ) { int i, m, t, k ; for(i=0;i<2;i++) {

/**********found**********/ m=0;

for(k=i+1;k

/**********found**********/ if(a[k]>a[m]) k=m;

t=a[i];a[i]=a[m];a[m]=t; } } 设计

请编写一个函数unsigned fun ,w是一个大与10的无符号整数,若w是n为的

整数,函数求出w的低n-1位的数作为函数值返回 例如 w为5923 则函数返回923;

16、B: tt tt.score[i] std M: m=i m=k

P: if(w>10000) w %= 10000 ; else if(w>1000) w %= 1000 ; else if(w>100) w %= 100 ; else if(w>10) w %=10 ; return w ; 17.填空

给定程序中,函数fun的功能是:对形参ss所指字符串数组中的M个字符串按长度由短到长进行排序。Ss所指字符串数组中共有M个字符串,且串长《N void fun(char (*ss)[N])

{ int i, j, k, n[M]; char t[N]; for(i=0; i

/**********found**********/ for(j=___1___; jn[j]) ___2___; if(k!=i)

{ strcpy(t,ss[i]); strcpy(ss[i],ss[k]); /**********found**********/ strcpy(ss[k],___3___); n[k]=n[i]; } } }

给定程序MODI。C中函数fun的功能是:判断ch中字符是否与str所指串中的某个字符相同;若相同,什么也不做,若不同,则将其插在串的最后 #include /**********found**********/ void fun(char str, char ch ) { while ( *str && *str != ch ) str++; /**********found**********/ if ( *str == ch ) { str [ 0 ] = ch;

/**********found**********/ str[1] = '0'; } }

设计

请编制一个函数fun,函数功能是吧s所指字符串中的内容逆值 17、B: i+1 k=j t M: char *str != 0

P: char b[N] ; int i = 0, j ; for(j = strlen(s) - 1 ; j >= 0 ; j--) b[i++] = s[j] ; b[i]=0; strcpy(s, b) ;

18.填空

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

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

double result=1.0; while (n>1 && n<170) /*********found*********/ result*=--n;

/*********found*********/ return _____; }

设计

历年全国计算机等级考试 - 二级C语言上机考试题库及答案

}修改给定程序MODI。C中函数fun的功能是:求k!(k<13),所求阶乘的值作为函数值返回,例如若(k=10,则应输出:3628800longfun(intk){/************found************/ifk>0return(k*fun(k-1));<
推荐度:
点击下载文档文档为doc格式
5meg700zsa83uyx977bp
领取福利

微信扫码领取福利

微信扫码分享