计算机二级C语言上机题库及答案(100套) 联系客服

发布时间 : 星期六 文章计算机二级C语言上机题库及答案(100套)更新完毕开始阅读

#define N 5 int fun ( int a[M][N] ) { } main( ) {

int aa[M][N]={{1,3,5,7,9}, {2,9,9,9,4}, {6,9,9,9,8}, {1,3,5,7,0}}; int i, j, y; FILE *out;

printf ( \ for ( i=0; i

for ( j=0; j

y = fun ( aa );

printf( \sum: %d\\n\ printf(\

out = fopen(\ fprintf(out, \y);

fclose(out); } 答案是:

int fun (int a[M][N]) {

int i,j,s=0; for( j=0;j

s+=a[0][ j]; s+=a[M-1][ j]; }

for(i=1;i<=M-2;i++) {

s+=a[i][0]; s+=a[i][N-i]; } return s; }

第 15 套

填空题

给定程序的功能是判断字符 ch 是否与串 str 中的某个字

符相同;若相同,什么也不做,若不同,则插在串的最后。 注

意:部分源程序给出如下

请勿改动主函数 main 和其他函数中的任何内容,仅在

横线上填如所编写的若干表达式或语句。

试题程序: #include #include Void fun(char*str,char ch) { while( str[0]=ch; _2_=0;

}

} Main() {

char s[81], c;

Printf(“\\nplease enter a string:\\n”);gets(s); Printf(“\\nplease enter the character to search :”); C=getchar(); Fun(_3_);

Printf(“\\nThe result is%s\\n”, s);

*str&&*str!=ch) str++; If(*ste_1_ch)

{

}

第 1 处填空:!=

第 2 处填空:str[1]或*(str+1) 第 3 处填空:s,c

改错题

下列给定程序中,函数 FUN 的功能是:判断字符 CH 是否与

则将其插在串的最后。

请改正程序中的错误,使它能得出正确结果。

注意:不要改动 MAIN 函数,不得增行或删行,也不要更改程 序的结构!

试题程序:#include

#include #include /********found********/ void fun(char {

while (*str && *str!=ch) str++;

/********found********/ if (*str == ch) {

str, char ch)

str[0] = ch;

/********found********/ str[1] = '0'; } } main() {

char s[81], c;

printf(\ gets(s);