SPARSE MATRIX
#include<stdio.h>
#include<conio.h>
int main()
{
typedef struct sparse
{
int row;
int col;
int value;
}stype;
stype s[10];
int i,j,k=1,x;
printf("\n enter matrix elements one by one\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&x);
if(x!=0)
{
s[k].row=i;
s[k].col=j;
s[k].value=x;
k++;
}
}
}
printf("\n ROW \t COL \t VALUE ");
for(i=1;i<k;i++)
printf("\n %d \t %d \t %d",s[i].row,s[i].col,s[i].value);
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
typedef struct sparse
{
int row;
int col;
int value;
}stype;
stype s[10];
int i,j,k=1,x;
printf("\n enter matrix elements one by one\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&x);
if(x!=0)
{
s[k].row=i;
s[k].col=j;
s[k].value=x;
k++;
}
}
}
printf("\n ROW \t COL \t VALUE ");
for(i=1;i<k;i++)
printf("\n %d \t %d \t %d",s[i].row,s[i].col,s[i].value);
getch();
return 0;
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.