#include<stdio.h> #include<conio.h> void main() { int A[10][10],B[10][10],row,col,s=0,i,j; printf("\nEnter the row x column size of the sparse matrix\n"); scanf("%d%d",&row,&col); printf("\nEnter the elements in the sparse matrix(mostly zeroes)\n"); for(i=0;i<row;i++)//and for i is the { for(j=0;j<col;j++) { printf("\nrow %d and column %d: ",i,j); scanf("%d",&A[i][j]); } } printf("\n\nThe given matrix is:\n"); for(i=0;i<row;i++) { for(j=0;j<col;j++) { printf("%d ",A[i][j]); } printf("\n"); } for(i=0;i<row;i++) { for(j=0;j<col;j++) { if(A[i][j]!=0) { B[s][0]=A[i][j]; B[s][1]=i; B[s][2]=j; s++; } } } printf("\n\nThe sparse matrix is given by VALUE, ROW, COLUMN"); for(i=0;i<s;i++) { for(j=0;j<3;j++) { printf("%d ",B[i][j]); } printf("\n"); } getch(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)