首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC++2010打开考生文件夹下prog1中的解决方案。此解决方案的项目中包含一个源程序文件prog1.c。在此程序中,定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N],int m),该函数的功能是使数组右上半三角元
使用VC++2010打开考生文件夹下prog1中的解决方案。此解决方案的项目中包含一个源程序文件prog1.c。在此程序中,定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N],int m),该函数的功能是使数组右上半三角元
admin
2018-08-11
33
问题
使用VC++2010打开考生文件夹下prog1中的解决方案。此解决方案的项目中包含一个源程序文件prog1.c。在此程序中,定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N],int m),该函数的功能是使数组右上半三角元素中的值乘以m。
例如,若m的值为2,a数组中的值为:
则返回主程序后a数组中的值应为:
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N5
void fun(int a[][N],int m)
{
}
main()
{
int a[N][N],m,i,j;
FILE*out;
printf("***The array***\n");
for(i=0;i<N;i++)
{for(j=0;j<N;j++)
{a
[j]=rand()%20;
printf("%4d",a
[j]);
}
printf("\n");
}
m=rand()%4;
printf("m=%4d\n",m);
fun(a,m);
printf("THE RESULT\n");
for(i=0;i<N;i++)
{for(j=0;jj<N;j++)
printf("%4d",a
[j]);
printf("\n");
}
/*********found*********/
out=fopen("out.dat","w");
for(i=0;i<N;i++)
for(j=0;j<N;j++)
a
[j]=i*j;
fun(a,8);
for(i=0;i<N;i++)
{for(j=0;j<N;j++)
fprintf(out,"%4d",a
[j]);
fprintf(out,"\n");
}
fclose(out);
/*********found*********/
}
选项
答案
void fun(int a[][N],int m) { int i,j; for(j=0;j<N;j++) for(i=0;i<=j;i++) a[i][j]=a[i][j]*m; /*右上半三角元素中的值乘以m*/ }
解析
本程序实现将矩阵中右上半三角元素中的值乘以m,使用循环语句遍历数组元素,第1个循环用于控制行坐标,第2个循环用于控制列下标。
转载请注明原文地址:https://kaotiyun.com/show/Djxp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
按照“先进先出”的原则组织数据的结构是______。
设有说明int(*ptr)[M];其中的标识符ptr是______。
若有以下定义:intt[3][2];,能正确表示t数组元素地址的表达式是______。
循环控制语句“while(!scanf("%d",&i))getchar();”执行的情况是()
在结构化分析使用的数据流图中,使()解释其中的图形元素。
fwrite函数的一般调用形式是
结构化程序设计主要强调的是______。
已定义ch为字符型变量,以下赋值语句中错误的是()。
语句:x++;、++x;、x=x+1;、x=1+x;,执行后都使变量x中的值增1,请写出一条同一功能的赋值语句(不得与列举的相同)【】。
静态测试是一种重要的测试方式,可以发现30%到70%的逻辑设计和编码错误。下面()不属于静态测试?
随机试题
下列关于第二审程序的说法中,错误的有哪些?()
小王在回家途中遇到劫匪,情急之下,捡起一块砖头砸向匪徒的行为属于紧急避险。()
试论述运用奖励激励与惩罚激励时应注意的问题。
Thehumannoseisanunderratedtool.Humansareoftenthoughttobeinsensitivesmellerscomparedwithanimals,【56】thisislarg
血液病患者易于继发感染的部位主要有
污染物被生物吸收后,在生物体内蓄积,使体内的浓度大大超过环境中的浓度,这种转归形式称为污染物通过化学反应或生物降解作用,改变了毒性、存在状态和迁移能力,这种转归形式称为
关于女儿墙的构造设计,下列哪一项说法是正确无误的?[2001—074]
下列哪篇文章把中国第一个十年的新诗分为自由派、格律派、象征派?()
在C语言中,以下选项中不能正确表示10×1000之值的是()。
TheDeliveryofHumorI.UnderstandingdeliveryA.definition:theabilityofthespeakertopresentthehumorousmaterialinth
最新回复
(
0
)