稀疏矩阵

来源:百度知道 编辑:UC知道 时间:2024/05/30 13:49:00
用三元组顺序表存储一个3行4列的稀疏矩阵,并对其进行转置。
输入:构造稀疏矩阵的相关信息
输出:原稀疏矩阵和转置后的矩阵,输出格式如下
例:原矩阵:
0 1 0
2 0 0
0 0 0
转置后的矩阵:
0 2 0
1 0 0
0 0 0

/*******************
*
** The prgrom's function is to achieve the matrix convert from M*N to N*M)
*** Debug by : Turbo 2.0
************************/
#define M 4
#define N 3
#include<stdio.h>
main()
{
int i,j;
int a[M][N],b[N][M];
printf("Enter the 2*3 matrix:\n");
for(i=0;i<M;i++) /* input the array 'a' */
{
for(j=0;j<N;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<M;i++) /* out the array 'a' */
{
for(j=0;j<N;j++)
printf("%3d",a[i][j]);
printf("\n");
}
printf("\n");
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
b[j][i]=a[i][j]; /* exchange the row and line */
}
}
for(i=0;i<N;i++)