c program for sparse matrix using array
02:44/*Represent sparse matrix using array and perform matrix addition,simple
transpose and fast transpose */
output :>
1)Read the First Sparse Matrix
2)Read the second sparse matrix
3)Display the first matrix
4)Display the second matrix
5)Addition of two matrices
6)Simple transpose of the first matrix
7)Fast transpose of the first matrix
8)Quit
Enter your choice : 1
Enter the size of matrix (rows,columns):2 2
Enter no. of non-zero elements:3
Enter the next triple(row,column,value):2 3 5
Enter the next triple(row,column,value):0 2 1
Enter the next triple(row,column,value):2 5 8
1)Read the First Sparse Matrix
2)Read the second sparse matrix
3)Display the first matrix
4)Display the second matrix
5)Addition of two matrices
6)Simple transpose of the first matrix
7)Fast transpose of the first matrix
8)Quit
Enter your choice : 3
rows = 2 columns = 2
2 3 5
0 2 1
2 5 8
Enter your choice : 2
Enter the size of matrix (rows,columns):2 2
Enter no. of non-zero elements:3
Enter the next triple(row,column,value):4 5 7
Enter the next triple(row,column,value):3 5 9
Enter the next triple(row,column,value):3 0 3
1)Read the First Sparse Matrix
2)Read the second sparse matrix
3)Display the first matrix
4)Display the second matrix
5)Addition of two matrices
6)Simple transpose of the first matrix
7)Fast transpose of the first matrix
8)Quit
Enter your choice : 5
rows = 2 columns = 2
2 3 5
0 2 1
2 5 8
4 3 5
3 2 1
3 5 8
1)Read the First Sparse Matrix
2)Read the second sparse matrix
3)Display the first matrix
4)Display the second matrix
5)Addition of two matrices
6)Simple transpose of the first matrix
7)Fast transpose of the first matrix
8)Quit
Enter your choice : 8
HomeWork 3.
ReplyDelete1. Write a c code for a sparse matrix multiplication. The sparse matrix should be implemented as a multi-linked structure.
1) Matrix dimension is NxN (N=10).
2) More than 20% elements of NxN matrix are not zero.
(ex)
3) Nonzero positons (x and y indexes) should be selected randomly.
4) Put random numbers for non-zero positions.
(show the position index and elements number on the monitor)
(ex)
Col row val
1 3 9
2 2 10
2 5 19
……
*for 3) and 4) used linear arrays.
5) Generated a doubly-linked list (DLL) for two sparse matrices and save the matrices in DLL..
6) Do matrix multiplication for the tow sparse matrices.
7) Print out the matrix in a regular form.
8) When you close the matrix, free the memory for linked-list.