Page 323 - Computer science 868 Class 12
P. 323
39 if(zeros > (r*c)/2)
40 {
41 System.out.println("The matrix is a sparse matrix");
42 }
43 else
44 {
45 System.out.println("The matrix is not a sparse matrix");
46 }
47 }
48 void display()
49 {
50 int i,j;
51 for(i=0; i<r; i++)
52 {
53 for(j=0; j<c; j++)
54 {
55 System.out.print(mat[i][j]+ " ");
56 }
57 System.out.println();
58 }
59 }
60 public static void main(String args[])
61 {
62 Sparse_Matrix ob = new Sparse_Matrix();
63 ob.input();
64 ob.display();
65 ob.check_sparse();
66 }
67 }
The output of the preceding program is as follows:
Enter the number of rows : 3
Enter the number of columns : 4
Enter the elements of the matrix:
1 0 0 0 0 1 0 0 0 0 1 1
321
Arrays 321

