對稱矩陣的壓縮算法

usin in in

#include <iostream>
using namespace std;
const int N = 5;
int main( )
{
int a&#91;N&#93;&#91;N&#93;, sa&#91;N * (N + 1) / 2&#93; = {0};
int i, j;
cin>>i;
for (i = 0; i < N; i++)
for (j = 0; j <= i; j++)
a&#91;i&#93;&#91;j&#93; = a&#91;j&#93;&#91;i&#93; = i + j;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
cout<<a&#91;i&#93;&#91;j&#93;<<" ";
cout<<endl;
}
for (i = 0; i < N; i++)
for (j = 0; j <= i; j++)
SA&#91;i * (i - 1)/2 + j&#93; = a&#91;i&#93;&#91;j&#93;; //壓縮存儲
cout<<"請輸入行號和列號:";
cin>>i>>j;
cout<<i<<"行"<<j<<"列的元素值是:";
if (i >= j)
cout<<SA&#91;i * (i - 1)/2 + j&#93;<<endl;
else
cout<<SA&#91;j * (j - 1)/2 + i&#93;<<endl;
return 0;
}

相關詞條

熱門詞條

聯絡我們