首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如:二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1
请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如:二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1
admin
2015-08-23
33
问题
请编写函数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的花括号中填入你编写的若干语句。
#inolude
#define M 4
#define N 5
int fun(int a[M][N])
{
}
main()
{ int aa[1][N]={{1,3,5,7,9),f 2,9,
9,9,4},{6,9,9,9,8),{1,3,5,7,0));
int i,j,y;void NONO();
printf ("The original data is;\n");
for (i=0; i
{ for(j=0 ; j
("%6d",aa
[j]);
printf("\n");
y=fun(aa);
printf("\nThe s1im:%d\n",y);
printf("\n");
NONO();
}
void NONO()
{/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。 */
int i, j, y, k, aa[M][N] ;
FILE*rf,*wf;
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(k=0;k<1 0;k++) {
for(i=0 ; i
for(j=0;j
"%d",&aa
[j]);
y=fun(aa);
fprintf(wf,"%d\n",y);
)
fclose(rf);
fclose(wf);
}
选项
答案
int tot=0, i, j; for(i=0; i
解析
进入fun函数,根据前面的分析:求周边元素的和,可以采用两个循环分别把行元素和列元素相加。但要避免把周边元素重复相加。
转载请注明原文地址:https://kaotiyun.com/show/BHDp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
以下程序运行后的输出结果是【】。main(){intx=1,y=0,a=0,b=0;switch(x){case1:switch(y){case0:a++;break;
若x和a均是血型变量,则计算完x=(a=4,6*2)后的x值为______。
有以下程序:main(){inti=0,s=0;for(;;){if(i==3||i==5)continue;if(i==6)break;i++;
有以下程序:main(){chars[]="ABCD",*p;for(p=s+1;p<s+4;p++)printf("%s\n",p);}程序运行后的输出结果是______。
下面程序的功能是:将字符数组a中下标值为偶数的元素从小到大排列,其他元素不变。请填空。#include#includemain(){chara[]="clanguage",t;inti,j,k;k=strlen(a);f
以下程序用于判断a、b、c能否构成三角形,若能,输出YES,否则输出NO。当给a、b、c输入三角形三条边长时,确定a、b、c能构成三角形的条件是需同时满足三个条件:a+b>c,a+c>b,b+c>a。请填空。main(){floata,b
数据结构分为线性结构和非线性结构,带链的队列属于【】。
已有定义:charc;,程序前面已在命令行中包含ctype.h文件,不能用于判断c中的字符是否为大写字母的表达式是
利用fseek函数可实现的操作是()。
若要用函数fopen打开一个新的二进制文件,该文件要既能读也能写,则应以哪种方式打开文件()。
随机试题
符合淋巴瘤分期B组包括
正常颈外动脉血流频谱是下列哪种形态:
睾丸间质细胞的主要生理功能是
具有清热生津,止呕,除烦功效的药物是
按《企业所得税法》规定,以下可作为应税所得准予扣除的项目是()。
甲企业2009年的普通股和长期借款资金分别为1500万元和900万元,资金成本分别为18%和8%。2008年度拟再向银行借入600万元,年利率为12%,筹资费用率为2%;预计借款后企业的股票价格变为每股30元,年末每股股利4元,股利增长率为2%。若企业
拆迁出租房屋时,被拆迁人与房屋承租人对解除租赁关系达不成协议的,应当实行()。
母乳中的补体可以直接杀灭和降解细菌。()
受教育者既是教育的对象,又是学习和发展的客体,也是构成教育活动的基本要素。()
Inmathematics,judgmentsaboutthevalidityofproofsaremediatedbypeer-reviewedjournals,toensure______,reviewersarec
最新回复
(
0
)