Sparse Matrix C Program

Wednesday, 4 September 2013

#include<stdio.h>
#include<conio.h>
struct term
{
int row,col,val;
};
struct term e[100];
void main()
{
int i,j,k=1,r,c,a[10][10];
clrscr();
printf("enter the row \n");
scanf("%d",&r);
printf("enter the col \n");
scanf("%d",&c);
printf("enter the element \n");
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{if(a[i][j]!=0)
{
e[k].row=i;
e[k].col=j;
e[k].val=a[i][j];
k++;
}}
printf("\n row \t col \t val \t");
for(i=1;i<k;i++)
{
printf("\n %d\t %d\t %d\t",e[i].row,e[i].col,e[i].val);
}
getch();
}

OUTPUT:-

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
Related Posts Plugin for WordPress, Blogger...
 

Most Reading

Labels