首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请编写函数fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如,若二维数组中的值为: 1 3 5 7 9 2 9 9 9 4
请编写函数fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如,若二维数组中的值为: 1 3 5 7 9 2 9 9 9 4
admin
2016-12-06
24
问题
请编写函数fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
例如,若二维数组中的值为:
1 3 5 7 9
2 9 9 9 4
6 9 9 9 8
1 3 5 7 0
则函数值为61。
注意:部分源程序在文件PROG1.C中。
请勿改主动函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
1 #include<conio.h>
2 #include<stdio.h>
3 #include<stdlib.h>
4 #defihe M 4
5 #defihe N 5
6 int fun(int a[M][N])
7 {
8
9 }
10 void main()
11 {
12 FILE*wf;
13 int aa[M][N]={{1,3,5,7,9},{2,9,9,9,4},{6,9,9,9,8},{1,3,5,7,0}};
14 int i,j,y;
15 aystem(’’CLS’’);
16 printf(’’The origina1 data is:\n’’);
17 for(i=0;i
18 {for(j=0 ; j
19 printf(’’%6d’’,aa
[j]);
20 printf(’’\n’’);
21 }
22 y=fun(aa);
23 printf(’’\nThe sun:%d\n’’,y);
24 printf(’’\n’’);
25 /*****************/
26 wf=fopen(’’out.dat’’,’’w’’);
27 fprintf(wf,’’%d’’,y);
28 fclose(wf);
29 /*****************/
30 }
选项
答案
1 int fun(int a[M][N]) 2 { 3 int i,j,sum=0; 4 for(i=0;i
解析
本题采用逐一判断的方式。二维数组周边元素的规律是,其两个下标值中一定有一个是0或M-1或N-1。程序中循环语句用来控制数组的行和列,条件语句用来判断数组元素是否为周边元素。
转载请注明原文地址:https://kaotiyun.com/show/2NDp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
在函数调用过程中,如果函数funA调用了函数funB,函数funB又调用了函数funA,则______。
以下程序段中,能够通过调用函数fun,使main函数中的指针变量p指向一个合法的整型单元的是______。
有以下程序:main(){intnum[4][4]={{1,2,3,4),{5,6,7,8),{9,10,11,12),{13,14,15,16}},i,j;for(i=0;i
以下程序从终端读入数据到数组中,统计其中正数的个数,并计算它们之和。请填空。main(){inti,a[20],sum,count;sum=count=0;for(i=0;i<20;i
已定义以下函数:fun(int*p){return*p;}该函数的返回值是______。
有以下程序:main(){inta[3][3],*p,i;p=&a[0][0];for(i=0;i<9;i++)p[i]=i;for(i=0;i<3;i++)printf("%d",a[1][
有以下程序中若有如下说明和定义语句;charfun(char*);main(){char*s="one",a[5]={0},(*f1)()=fun,ch;…}以下选项中对函
以下程序的功能是:给r输入数据后计算半径为r的圆面积s。程序在编译时出错。main()/*Beginning*/{intr;floats;scanf("%d",&r);s=*π*r*r*r;printf("
以下选项中可以作为C语言中合法整数的是______。
有以下函数:fun(char*a,char*b){while((*a!=’\0’)&&(*b!=’\0’)&&(*a==*b)){a++;b++;}return(
随机试题
陈述性知识习得速度慢,遗忘也慢;程序性知识习得速度快,遗忘也快。()
DSL(DIGITALSUBSCRIBER、LINE)是指:
A、清热解毒,凉血止血,利湿退黄B、清热解毒,息风止痉,清肝明目C、清热解毒,消肿止痛,凉肝定惊D、清热解毒,消痈散结,通经下乳重楼的功效是()。
我国生活饮用水的卫生标准(GB5749-2006)中规定
患儿,8岁,上前牙外伤折断1小时。局部检查右上中切牙牙冠斜折,切角缺损,牙髓暴露,触痛明显,松动(一)。首选的治疗是
结脉、代脉、促脉,其脉象的共同点是
某股份有限公司发行新股,其实施的下列行为中,符合公司法律制度关于股票发行规定的是()。
信息系统安全风险的评估方法是()。
A、 B、 C、 D、 A每个图形中都只有一条直线,其余线条均为曲线。
WhenIaminaserioushumor,IveryoftenwalkbymyselfinWestminsterAbbey,wherethegloominessoftheplace,andtheuset
最新回复
(
0
)