C语言上机题库百科园第5章!南信大! 联系客服

发布时间 : 星期四 文章C语言上机题库百科园第5章!南信大!更新完毕开始阅读3ecc8954a6c30c2258019e21

{

for(j=2;j=i) aa[k++]=i; }

return k;

/*请编写函数fun,函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。

例如,若二维数组中的值为 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1 3 5 7 0 则函数值为61。

注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:*/

#include #include #define M 4 #define N 5

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

/***************Begin************/

/*************** End ************/

}

void main() {

FILE *wf;

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

printf (\ for(i=0; i

{for (j=0; j

printf(\ printf(\ }

y=fun(aa);

printf(\

printf(\

/******************************/ wf=fopen(\ fprintf (wf,\ fclose(wf);

/*****************************/ }

【参考代码】 int i,j,sum=0; for(i=0;i

if(i==0||i==M-1||j==0||j==N-1) sum=sum+a[i][j];

return sum;

/*编写一个函数,从传入的num个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标志)。 注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:*/

#include #include #include

void fun(char a[][81], int num, char max[]) {

/***************Begin************/ /*************** End ************/ }

void main() {

FILE *wf;

char ss[10][81],ps[81];

char s[3][81]={\ int i=0,n;

printf(\输入若干个字符串:\ gets(ss[i]); puts(ss[i]);

while(!strcmp(ss[i], \用4个星号作为结束输入的标志*/ { i++;

gets(ss[i]); puts(ss[i]); } n=i;

fun(ss,n,ps);

printf(\/******************************/ wf=fopen(\ fun(s,3,p);

fprintf(wf,\ fclose(wf);

/*****************************/ }

【参考代码】

int i=0;

strcpy(max,a[0]); /*找出最长的一个字符串*/ for(i=0;i

if(strlen(max)

/*请编写一个函数fun,它的功能是:求出1到m(含m)之内能被7或11整除的所有整数放在数组a中,通过n返回这些数的个数。

例如,若传给m的值为50,则程序输出: 7 11 14 21 22 28 33 35 42 44 49 注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序: */

#include #include #define M 100

int fun(int m, int a[]) {

/***************Begin************/ /*************** End ************/

}

void main() {

FILE *wf;

int aa[M],n,k; n=fun(50,aa); for(k=0;k

if((k+1) ==0) /*每行输出20个数*/ {printf(\ printf(\ } else

printf(\ printf(\

/******************************/ wf=fopen(\ for(k=0;k

fprintf(wf,\ fclose(wf);

/*****************************/ }

【参考代码】 int i,j=0; for(i=1;i<=m;i++) if(i%7==0||i==0) a[j++]=i;

return j; /*返回这些数的个数*/

/*请编写一个函数fun,它的功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转为整数的函数)。

例如,若输入字符串\则函数把它转换为整数值-1234。 注意:部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:*/

#include #include long fun(char p[]) {

/***************Begin************/ /*************** End ************/

}

void main() {

FILE *wf; char s[6]; long n;

printf(\ gets(s); n=fun(s);

printf(\

/******************************/