Array-promo
Matrix-promo

Question

Program to determine whether a given matrix is a sparse matrix.

A matrix is said to be a sparse matrix if most of the elements of that matrix are 0. It implies that it contains very few non-zero elements.
For the matrix to be sparse, more than half of the elements present in the matrix must be zero.

				
					Enter number of rows in Matrix:4
Enter number of columns in Matrix:3
Enter elements in matrix:
( 1 , 1 ) :1
( 1 , 2 ) :0
( 1 , 3 ) :1
( 2 , 1 ) :1
( 2 , 2 ) :1
( 2 , 3 ) :0
( 3 , 1 ) :0
( 3 , 2 ) :1
( 3 , 3 ) :1
( 4 , 1 ) :0
( 4 , 2 ) :0
( 4 , 3 ) :1
Matrix:
[1 0 1]
[1 1 0]
[0 1 1]
[0 0 1]
Given Matrix is not a Sparse Matrix



Enter number of rows in Matrix:3
Enter number of columns in Matrix:3
Enter elements in matrix:
( 1 , 1 ) :0
( 1 , 2 ) :0
( 1 , 3 ) :1
( 2 , 1 ) :0
( 2 , 2 ) :9
( 2 , 3 ) :0
( 3 , 1 ) :0
( 3 , 2 ) :0
( 3 , 3 ) :0
Matrix:
[0 0 1]
[0 9 0]
[0 0 0]
Given Matrix is Sparse Matrix

				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *