fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. #define MAX_TERMS 30
  5. #define MAX_SIZE 10
  6.  
  7. typedef struct {
  8. int r;
  9. int c;
  10. int val;
  11. } term;
  12.  
  13. typedef struct {
  14. int numRow;
  15. int numCol;
  16. int numEle;
  17. term listEle[MAX_TERMS];
  18. } sparse_matrix;
  19.  
  20. void createSparseMatrix(int Matrix[][MAX_SIZE],sparse_matrix* sMatrix){
  21. int paracol,pararow;
  22. int x=0;
  23. int row;
  24. int col;
  25. sMatrix->numCol=col;
  26. sMatrix->numRow=row;
  27.  
  28. for(pararow=0;pararow<row;pararow++){
  29. for(paracol=0;paracol<col;paracol++){
  30. if(Matrix[pararow][paracol]!=0){
  31. sMatrix->listEle[x].r=pararow;
  32. sMatrix->listEle[x].c=paracol;
  33. sMatrix->listEle[x].val=Matrix[pararow][paracol];
  34. x++;
  35. }
  36. }
  37. }
  38. sMatrix->numEle = x;
  39. }
  40.  
  41. int main() {
  42. return 0;
  43. }
Success #stdin #stdout 0s 1828KB
stdin
Standard input is empty
stdout
Standard output is empty