fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int i,j,sum=0;
  6. int r;cin>>r;
  7. int c;cin>>c;
  8. int a[r][c];
  9. for(i=0;i<r;i++)
  10. {
  11. for(j=0;j<c;j++)
  12. {
  13. scanf("%d",&a[i][j]);
  14. }
  15. }
  16. for(i=0;i<r;i++)
  17. {
  18. for(j=0;j<c;j++)
  19. {
  20. if(a[i][j]==0)
  21. {
  22. sum++;
  23. }
  24. }
  25. }
  26. if(sum>r*c/2)
  27. {
  28. cout<<"The given matrix is sparse matrix"<<endl;
  29. }
  30. cout<<"There are "<<sum<<" number of zeroes in the matrix";
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5336KB
stdin
2
2
0
0
1
0
stdout
The given matrix is sparse matrix
There are 3 number of zeroes in the matrix