Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- class sparse
- {
- int a[5][5];
- public:void convert(void);
- };
- void sparse::convert(void)
- {
- int m,n,i,j, b[10][3],count=0;
- cout<<"\n enter rowsize and column size:"<<endl;
- cin>>m>>n;
- cout<<"\n enter the elements of the matrix:"<<endl;
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- cin>>a[i][j];
- if(a[i][j]!=0)
- {
- count++;
- b[count][0]=i;
- b[count][1]=j;
- b[count][2]=a[i][j];
- }
- }
- b[0][0]=m;
- b[0][1]=n;
- b[0][2]=count;
- cout<<"\n sparse representation:";
- for(i=0;i<=count;i++)
- {
- cout<<"\n";
- for(j=0;j<3;j++)
- {
- cout<<b[i][j]<<"\t";
- }
- }
- }
- }
- int main()
- {
- clrscr();
- sparse obj;
- obj.convert();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement