数据结构之矩阵解压

  • 格式:txt
  • 大小:2.27 KB
  • 文档页数:1
{
cin >> a[i];
}
for (i = 0; i<10; i++)
{
cin >> b[i];
}
cout << "矩阵a" << endl; display(a);
cout << "矩阵b" << endl; display(b);
uncompress(a, a1);
for (i = 0; i<4; i++)
{
for (j = 0; j<4; j++)
cout << a1[i][j] << " ";
cout << endl;
}//输出还原后的矩阵
}
//对压缩对称矩阵解压
void uncompress(int a[10], int a1[4][4])
{
int t;
int i = 0, j = 0;
for (t = 0; t<10; t++)
{
a1[i][j] = a[t];
if (i == j)
{
i++;
j = 0;
}
else if (i != j)
j++;
}//赋值下三角
j = 0;
}
else if (i != j)
j++;
}//赋值下三角
for (i = 0; i<4; i++)
{
for (j = 0; j<4; j++)
if (i >= j)
a1[j][i] = a1[i][j];
}//补全矩阵
for (n = 0; n < 4; n++)
{
s = a1[j][n] * b1[n][m];
c = c + s;
}
e[j][x] = c;
x++;
}
}
for (i = 0; i < 4; i++)
{
uncompress(a, a1);
uncompress(b, b1);
int e[4][4],i,j,m,n,c,s,x;
for (j = 0; j < 4; j++)
{
x = 0;
for (m = 0; m < 4; m++)
{
c = 0;
}
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
cout << c[i][j]<<" ";
cout << endl;
}
}
//计算矩阵乘积
void multiplication(int a[], int a1[4][4], int b[], int b1[4][4])
{
for (j = 0; j < 4; j++)
cout << e[i][j] << " ";
cout << endl;
}
}
void main()
{
int a[10], b[10], i, j, a1[4][4], b1[4][4];
for (i = 0; i<10; i++)
/*1.已知A和B是两个n×n阶的对称矩阵,输入时,对称矩阵只输入下三角元素,存入一维数组。编写一个程序实现如下功能:(可参考实验指导书实验6.3)
① 求对称矩阵A和B的和。
② 求对称矩阵A和B的乘积。*/
#include<iostream>//定义头文件
using namespace s[4] = {0};
uncompress(a, a1);
uncompress(b, b1);
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
c[i][j] = a1[i][j] + b1[i][j];
void display(int a[]) // 压缩对称矩阵解压、输出
{
int t, a1[4][4];
int i = 0, j = 0;
for (t = 0; t<10; t++)
{
a1[i][j] = a[t];
if (i == j)
{
i++;
for (i = 0; i<4; i++)
{
for (j = 0; j<4; j++)
if (i >= j)
a1[j][i] = a1[i][j];
}//补全矩阵
}
void madd(int a[],int a1[4][4] ,int b[],int b1[4][4]) //对称矩阵A和B的和
uncompress(b, b1);
cout << "矩阵之和" << endl;
madd(a, a1, b,b1);
cout << "矩阵之积" << endl;
multiplication(a, a1, b, b1);
}

下载文档原格式

  / 1