#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
int i, j, p;
float arr1[3][3], arr2[3][3], arr[3][3], arr0[3][3] = { 0 };
printf("请输入两个三行三列的矩阵:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
scanf("%f", &arr1[i][j]);
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
scanf("%f", &arr2[i][j]);
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
arr[i][j] = arr1[i][j] + arr2[i][j];
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
for (p = 0; p < 3; p++)
arr0[i][j] += arr1[j][p] * arr2[p][j];
}
printf("矩阵的和为:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
printf("%7.2f", arr[i][j]);
printf("\n");
}
printf("矩阵乘积为:\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
printf("%7.2f", arr0[i][j]);
printf("\n");
}
return 0;
}
标签:arr,++,矩阵,arr2,arr1,printf From: https://blog.51cto.com/u_16073189/6378087