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][3];
- public: void transpose(void);
- };
- void sparse::transpose(void)
- {
- int m,n,i,j,b[10][3],count;
- cout<<"\nEnter row and column size"<<endl;
- cin>>m>>n;
- cout<<"\nEnter no: ofnon zero elements";
- cin>>count;
- cout<<"\nEnter elements of the matrix"<<endl;
- for(i=0;i<=count;i++)
- {
- for(j=0;j<3;j++)
- {
- cin>>a[i][j];
- }
- }
- a[0][0]=m;
- a[0][1]=n;
- a[0][2]=count;
- cout<<"\nThe sparse representation:";
- for(i=0;i<=count;i++)
- {
- cout<<"\n";
- for(j=0;j<3;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- }
- for(i=1;i<=count;i++);
- {
- b[i][0]=a[i][1];
- b[i][1]=a[i][0];
- b[i][2]=a[i][2];
- }
- b[0][0]=n;
- b[0][1]=m;
- b[i][2]=count;
- cout<<"\nTranspose is:"<<endl;
- for(i=0;i<=count;i++)
- {
- cout<<endl;
- for(j=0;j<3;j++)
- {
- cout<<b[i][j]<<"\t";
- }
- }
- }
- int main()
- {
- clrscr();
- sparse obj;
- obj.transpose();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement