Advertisement
Hydrase

sparse trans

Aug 6th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. class sparse
  4. {
  5. int a[5][3];
  6. public: void transpose(void);
  7. };
  8. void sparse::transpose(void)
  9. {
  10. int m,n,i,j,b[10][3],count;
  11. cout<<"\nEnter row and column size"<<endl;
  12. cin>>m>>n;
  13. cout<<"\nEnter no: ofnon zero elements";
  14. cin>>count;
  15. cout<<"\nEnter elements of the matrix"<<endl;
  16. for(i=0;i<=count;i++)
  17. {
  18. for(j=0;j<3;j++)
  19. {
  20. cin>>a[i][j];
  21. }
  22. }
  23. a[0][0]=m;
  24. a[0][1]=n;
  25. a[0][2]=count;
  26. cout<<"\nThe sparse representation:";
  27. for(i=0;i<=count;i++)
  28. {
  29. cout<<"\n";
  30. for(j=0;j<3;j++)
  31. {
  32. cout<<a[i][j]<<"\t";
  33. }
  34. }
  35. for(i=1;i<=count;i++);
  36. {
  37. b[i][0]=a[i][1];
  38. b[i][1]=a[i][0];
  39. b[i][2]=a[i][2];
  40. }
  41. b[0][0]=n;
  42. b[0][1]=m;
  43. b[i][2]=count;
  44. cout<<"\nTranspose is:"<<endl;
  45. for(i=0;i<=count;i++)
  46. {
  47. cout<<endl;
  48. for(j=0;j<3;j++)
  49. {
  50. cout<<b[i][j]<<"\t";
  51. }
  52. }
  53. }
  54. int main()
  55. {
  56. clrscr();
  57. sparse obj;
  58. obj.transpose();
  59. getch();
  60. return 0;
  61. }
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement