The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Transs
By Guest on 21st September 2023 05:08:57 AM | Syntax: PYTHON | Views: 104



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. #include<iostream>
  2. using namespace std;
  3. class triplet
  4.  {
  5.         public:
  6.         int row,columns,value;
  7.  };
  8.  int main()
  9.  {
  10.         int rows,columns,count=0,index=0;
  11.         cout<<"enter of rows:";
  12.         cin>>rows;
  13.         cout<<"enter no of columns:";
  14.         cin>>columns;
  15.         int matrix[rows][columns];
  16.         cout<<"enter elements:";
  17.         for(int i=0;i<rows;i++)
  18.         {
  19.                 for(int j=0;j<columns;j++)
  20.                 {
  21.                         cin>>matrix[i][j];
  22.                 }
  23.          }
  24.  
  25.  for(int i=0;i<rows;i++)
  26.  {
  27.                 for(int j=0;j<columns;j++)
  28.                 {
  29.                         if (matrix[i][j]!=0)
  30.                         {
  31.                                 count++;
  32.                         }
  33.                 }
  34.         }
  35.         triplet tripleta[count];
  36.         for(int i=0;i<rows;i++)
  37.  {
  38.                 for(int j=0;j<columns;j++)
  39.                 {
  40.                         if (matrix[i][j]!=0)
  41.                         {
  42.                                 tripleta[index].row=i;
  43.                                 tripleta[index].columns=j;
  44.                                 tripleta[index].value=matrix[i][j];
  45.                                 index++;
  46.                         }
  47.                 }
  48.         }
  49.         triplet transposea[count];
  50.         for(int i=0;i<count;i++)
  51.         {
  52.         transposea[i].row=tripleta[i].row;
  53.         transposea[i].columns=tripleta[i].row;
  54.         transposea[i].value=tripleta[i].value;
  55.         }
  56.         cout<<"transpose:\n";
  57.         cout<<"row\tcolumn\tvalue:\n";
  58.         for(int i=0;i<count;i++)
  59.         {
  60.                 cout<<transposea[i].row<<"\t"<<transposea[i].columns<<"\t"<<transposea[i].value<<endl;
  61.         }
  62.         return 0;
  63. }





transs