- #include<iostream>
- using namespace std;
- class triplet
- {
- public:
- int row,columns,value;
- };
- int main()
- {
- int rows,columns,count=0,index=0;
- cout<<"enter of rows:";
- cin>>rows;
- cout<<"enter no of columns:";
- cin>>columns;
- int matrix[rows][columns];
- cout<<"enter elements:";
- for(int i=0;i<rows;i++)
- {
- for(int j=0;j<columns;j++)
- {
- cin>>matrix[i][j];
- }
- }
- for(int i=0;i<rows;i++)
- {
- for(int j=0;j<columns;j++)
- {
- if (matrix[i][j]!=0)
- {
- count++;
- }
- }
- }
- triplet tripleta[count];
- for(int i=0;i<rows;i++)
- {
- for(int j=0;j<columns;j++)
- {
- if (matrix[i][j]!=0)
- {
- tripleta[index].row=i;
- tripleta[index].columns=j;
- tripleta[index].value=matrix[i][j];
- index++;
- }
- }
- }
- triplet transposea[count];
- for(int i=0;i<count;i++)
- {
- transposea[i].row=tripleta[i].row;
- transposea[i].columns=tripleta[i].row;
- transposea[i].value=tripleta[i].value;
- }
- cout<<"transpose:\n";
- cout<<"row\tcolumn\tvalue:\n";
- for(int i=0;i<count;i++)
- {
- cout<<transposea[i].row<<"\t"<<transposea[i].columns<<"\t"<<transposea[i].value<<endl;
- }
- return 0;
- }