...输入3×3的矩阵ab和c,编写三个函数分别计算c=a+b,c=a-b,c=a*b...
发布网友
发布时间:2024-10-18 16:36
我来回答
共3个回答
热心网友
时间:2024-11-07 06:46
#include <stdio.h>
int main(void)
{
void output(int num[][3]);
int i, j;
int a[3][3], b[3][3], c[3][3];
puts("请输入矩阵a : ");
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
scanf("%d", a[i] + j);
}
puts("请输入矩阵b : ");
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
scanf("%d", b[i] + j);
}
puts("a+b : ");
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
c[i][j] = a[i][j] + b[i][j];
}
output(c);
puts("a-b : ");
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
c[i][j] = a[i][j] - b[i][j];
}
output(c);
puts("a*b : ");
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
c[i][j] = a[i][j] * b[i][j];
}
output(c);
return 0;
}
void output(int num[][3])
{
int i, j;
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
printf("%-5d", num[i][j]);
putchar('\n');
}
}
热心网友
时间:2024-11-07 06:39
#include<stdio.h>
void asum(double a[3][3],double b[3][3],double c[3][3])
{ int i,j; for ( i=0;i<3;i++ ) for ( j=0;j<3;j++ ) c[i][j]=a[i][j]+b[i][j];
}
void asub(double a[3][3],double b[3][3],double c[3][3])
{ int i,j; for ( i=0;i<3;i++ ) for ( j=0;j<3;j++ ) c[i][j]=a[i][j]-b[i][j];
}
void amul(double a[3][3],double b[3][3],double c[3][3])
{ int i,j; for ( i=0;i<3;i++ ) for ( j=0;j<3;j++ ) c[i][j]=a[i][j]*b[i][j];
}
void main()
{ double a[3][3],b[3][3],c[3][3];
int i,j;
for ( i=0;i<3;i++ ) for ( j=0;j<3;j++ ) scanf("%lf",&a[i][j]);
for ( i=0;i<3;i++ ) for ( j=0;j<3;j++ ) scanf("%lf",&b[i][j]);
printf("c=a+b\n");
asum(a,b,c); for ( i=0;i<3;i++,printf("\n") ) for ( j=0;j<3;j++ ) printf("%16lf",c[i][j]);
printf("c=a-b\n");
asub(a,b,c); for ( i=0;i<3;i++,printf("\n") ) for ( j=0;j<3;j++ ) printf("%16lf",c[i][j]);
printf("c=a*b\n");
amul(a,b,c); for ( i=0;i<3;i++,printf("\n") ) for ( j=0;j<3;j++ ) printf("%16lf",c[i][j]);
}
热心网友
时间:2024-11-07 06:45
a、b、c都是3*3的矩阵么?