#include<stdio.h>
#include<conio.h>
int main()
{
int a[10][10],b[10][10],m,n,s=0,i,j;
printf("\nEnter the order of m*n of the sparse matrix");
scanf("%d%d",&m,&n);
printf("Enter the elements in aparse matrix mostly zero\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\n%d row %d column",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nThe given matrix is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]!=0)
{
b[s][0]=a[i][j];
b[s][1]=a[i][j];
b[s][2]=a[i][j];
s++;
}
}
}
printf("\nThe sparse matrix is given by\n");
for(i=0;i<s;i++)
{
for(j=0;j<s;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
return 0;
}
#include<conio.h>
int main()
{
int a[10][10],b[10][10],m,n,s=0,i,j;
printf("\nEnter the order of m*n of the sparse matrix");
scanf("%d%d",&m,&n);
printf("Enter the elements in aparse matrix mostly zero\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\n%d row %d column",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nThe given matrix is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]!=0)
{
b[s][0]=a[i][j];
b[s][1]=a[i][j];
b[s][2]=a[i][j];
s++;
}
}
}
printf("\nThe sparse matrix is given by\n");
for(i=0;i<s;i++)
{
for(j=0;j<s;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
return 0;
}
can you give a proper snapshot of the output cuz its not running in my system.
ReplyDeleteoutput???
ReplyDelete