0% found this document useful (0 votes)
42 views2 pages

Sparse Transpose1

Uploaded by

apexop4480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Sparse Transpose1

Uploaded by

apexop4480
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

/*****************************SUBHAS NATH***************************/

/***********************************************************************/
/****** TRANSPOSE A SPARSE MATRIX (PROCEDURE-TRANSPOSE).******/

#include<stdio.h>
#include<conio.h>
int arr[30][3];
void main()
{
int i,j,r,c,ctr=0,a[10][10],count,k=1;
void t(void);
clrscr();
printf("\nEnter the row & column of the matrix:: ");
scanf("%d%d",&r,&c);
printf("\nEnter the matrix::\n");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
if(a[i][j]==0)
ctr++;
printf("\t%d",a[i][j]);
}
}
if(ctr>(r*c)/2)
printf("\nThe matrix is sparse matrix.");
else
printf("\nThe matrix is not sparse matrix.");
getch();
clrscr();
printf("\nRepresent the sparse matrix into tuple form::\n");
count=r*c-ctr;
arr[0][0]=r;arr[0][1]=c;arr[0][2]=count;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
if(a[i][j]!=0)
{
arr[k][0]=i;
arr[k][1]=j;
arr[k][2]=a[i][j];
k=k+1;
}
}
for(i=0;i<=count;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("\t%d",arr[i][j]);
}
t();
getch();
}

void t()
{
int p,q,col,m,n,t,b[20][3];
m=arr[0][0];n=arr[0][1];t=arr[0][2];
b[0][0]=n;b[0][1]=m;b[0][2]=t;
if(t<=0)
return;
q=1;
for(col=0;col<n;col++)
{
for(p=1;p<=t;p++)
{
if(arr[p][1]==col)
{
b[q][0]=arr[p][1];
b[q][1]=arr[p][0];
b[q][2]=arr[p][2];
q=q+1;
}
}
}
printf("\nTranspose matrix in tuple form::\n");
for(p=0;p<=t;p++)
{
printf("\n");
for(q=0;q<3;q++)
printf("\t%d",b[p][q]);
}
}

You might also like