Wednesday, 27 August 2014

PROGRAM

     /*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;
     }

2 comments:

  1. THIS IS NOT A SPARSE MATTRIX...PLEASE RUN THE PROGRAM PROPERLY BEFORE UPLOADING

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

Note: only a member of this blog may post a comment.