首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请编写函数fun,函数的功能是:将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。 例如,二维数组中的数据为: 则一维数组中的内容应是: 33 44 55 33 44 55 33 44 55 33 44 55。 注
请编写函数fun,函数的功能是:将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。 例如,二维数组中的数据为: 则一维数组中的内容应是: 33 44 55 33 44 55 33 44 55 33 44 55。 注
admin
2013-04-02
27
问题
请编写函数fun,函数的功能是:将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。
例如,二维数组中的数据为:
则一维数组中的内容应是:
33 44 55 33 44 55 33 44 55 33 44 55。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
void fun(int s[][10], int b[], int *n, int mm, int nn)
{
}
main()
{int w[10][10]={{33,33,33,33},{44,44,44,44},{55,55, 55,55}},i,j;
int a[100]={0}, n=0;void NONO ();
printf("The matrix:\n");
for(i=0; i<3; i++)
{for(j=0;j<4; j++)printf("%3d",w
[j]);
printf("\n");
}
fun(w,a,&n,3,4);
printf("The A array:\n");
for(i=0;i
);printf("\n\n");
NONO();
}
void NONO ()
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
FILE *rf, *wf ; int i, j, k ;
int w[10][10], a[100], n = 0, mm, nn ;
rf = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(k = 0 ; k < 5 ; k++) {
fscanf(rf, "%d %d", &mm, &nn);
for(i = 0 ; i < mm ; i++)
for(j = 0 ; j < nn ; j++) fscanf(rf, "%d", &w
[j]);
fun(w, a, &n, mm, nn);
for(i = 0 ; i < n ; i++) fprintf(wf, "%3d", a
); fprintf(wf, "\n");
}
fclose(rf); fclose(wf);
}
选项
答案
{ int i,j; for(j=0;j
解析
(1)利用两重循环,依次取矩阵中的元素。
(2)其中注意指针数组与数组指针的区别,其中数组指针s,它指向包含4个元素的一维数组。其数据元素的表示方式为:“*(*(s+i)+j)”。
转载请注明原文地址:https://kaotiyun.com/show/PJJp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
以下程序运行后的输出结果是【 】。main(){intx=0210;printf("%X\n",x);}
有以下程序: #include <stdio.h> main() {FILE *fp; int i,k,n; fp=fopen("data.dat","w+"); for(i=1;i<6;i++) {fprint
有以下程序: #include <strino.h> struct STU {int num; float TotalScore; }; void f(struct STU p) {struct STU
有以下程序: #include <string.h> main() {char p[]={’a’,’b’,’c’},q[10]={’a’,’b’,’c’}; printf("%d%d\n",strlen(p),strlen(q)
设有定义int a=2,b=3,c=4;,则以下选项中值为0的表达式是 ______。
以下程序的输出结果是[]。main(){inta[3][3]={{1,2,9},{3,4,8},{5,6,7}},i,s=0;for(i=0;i<3;i++)s+=-a[i][i]+a[i][3-i
有以下程序 #include <stdio.h> main() {char c1,c2,c3,c4,c5,c6; scanf("%c%c%c%c",&c1,&c2,&c3,&c4); c
设有以下语句 int a=1,b=2,c; c=a^(b<<2); 执行后,c的值为______。
对如下二叉树进行后序遍历的结果为______。
下面rotate函数的功能是:将n行n列的矩阵A转置为A’,例如:#defineN4voidrotate(inta()[N]){inti,j,t;f
随机试题
大雾天在高速公路遇事故不能继续行驶时怎样处置?
以下哪种疾病不属于结缔组织疾病:
脊柱侧凸最常见的类型是
中药全浸膏粉制颗粒,常选用的润湿剂是
项目还本资金来源主要有()。
按国家建设部规定,工程项目总造价中应预留()的尾留款作为质量保修费,待工程项目保修期结束后最后拨付。
2014年7月1日,某公司按面值发行总额为6000万元,期限为5年,票面年利率为5%,到期一次还本付息的债券。2015年12月31日,该债券的账面价值为()万元。
Toavoidthevariousfoolishopinionstowhichmanisliable,nosuperhumangeniusisrequired.Afewsimpleruleswillkeepyou
Menhavedistinguishedthemselvesfromotheranimals,andindoingsosecuredtheirsurvivalbytheabilitytoobserveandunder
Formanypeopletoday,readingisnolonger【S1】______.Tokeepuptheirworktheymustreadletters,reports,tradepublicatio
最新回复
(
0
)