Advertisement
Hydrase

Sparse rep

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