简答题 C语言
题号 #2257218

请编写函数proc().该函数的功能是:实现B=A+A7,即把矩阵A加上A的转置,存放在矩阵B中。计算结果在main ()函数中输出。 ’
例如,输入下面矩阵:
1 1 1
4 4 4
7 7 7
其转置矩阵为:
1 4 7
1 4 7
1 4 7
则程序输出:
2 5 8
5 8 11
8 11 14
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。 .
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void proc(int a[3][3],int b[3][3])
{

}
void main()
{  int arr[3][3]={{1,1,1),{4,4,4},{7,7,7}},
t[3][3];
int i,j。
system("CLS");
proc(arr,t);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%7d",t[i][j]);
printf("\n"):
}
}

进入在线模考

参考答案

暂无

答案解析

void proc(int a[3][3],int b[3][3])
{
int i,j;
for(i=0;i<3;i++) //从题目中可知'A'表示的
为a数组的行与列下标互换得到的数组
for(j=0;j<3;j++)

b[i][j]=a[i][J]+a[j][1]; //因此把互换的数组与原数组中的和放到b数组中
}

【解析】矩阵与其逆置矩阵的关系为:逆置矩阵中某一位置上的元素值为原矩阵中,行下标与列下标互换后的位置上的元素。根据这个特点求出各个位置上逆置矩阵中对应的值,进行相加并放在该位置上。

你可能感兴趣的试题

1 请补充main()函数,该函数的功能是:把文本文件text2中的内容追加到文本文件text1的内容之后。
例如,文件text2的内容为“I’m very happy!”,文件textl的内容为“I’m a girl,”,追加之后文件textl的内容为“I’m a girl,I’m very happy”。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数main()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define M 80
void main()
{
FILE*fp,*fp1,*fp2;
int i;
char c[M],ch;
system("CLS");
if((fp=fopen("text1.dat","r"))==NULL)
{
printf("file text1 cannot be opened\n");
exit(0);
}
printf("\n textl contents are:\n\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch:
putchar(c[i]);
}
fclose(fp);
if((fp=fopen("text2.dat","r"))==NULL)
{
printf("file text2 cannot be opened\n");
exit(0);
}
printf("\n\n\nB contents are:\n\n");
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]):
}
fclose(fp);
if((fp1=fopen("text1.dat","a")) 【1】 (fp2=
fopen("text2.dat","r")))
{
while((ch=fgetc(fp2))!=EOF)
【2】 ;
}
else
{
printf("Can not open textl text2 1\n");
}
fclose(fp2);
fclose(fp1);
printf("\n***"lew text1 contents***\n\n”);
if((fp=fopen("text1.dat","r"))==NULL)
{
printf("file text1 cannot be opened\n");
exit(0);
}
for(i=0;(ch=fgetc(fp))!=EOF;i++)
{
c[i]=ch;
putchar(c[i]):
}
【3】 ;
}
找试题 · 找答案 · 找资料 在线模考