My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
Resources » Articles/Knowledge Sharing » Computer & Technology »
C Program of sparse matrix for 3-tuple method using array
|
/* Program of sparse matrix for 3-tuple method using array*/ #include #define srow 50 #define mrow 20 #define mcolumn 20
main() { int mat[mrow][mcolumn],sparse[srow][3]; int i,j,nzero=0,mr,mc,sr,s; printf("Enter number of rows : "); scanf("%d",&mr); printf("Enter number of columns : "); scanf("%d",&mc);
for(i=0;i for(j=0;j { printf("Enter element for row %d,column %d : ",i+1,j+1); scanf("%d",&mat[i][j]); } printf("Entered matrix is : \n"); for(i=0;i { for(j=0;j { printf("%6d",mat[i][j]); if(mat[i][j]!=0) nzero++; } printf("\n"); }
sr=nzero+1; sparse[0][0]=mr; sparse[0][1]=mc; sparse[0][2]=nzero; s=1;
for(i=0;i for(j=0;j { if(mat[i][j]!=0) { sparse[s][0]=i+1; sparse[s][1]=j+1; sparse[s][2]=mat [i][j]; s++; } } printf("Sparse matrix is :\n"); for(i=0;i { for(j=0;j<3;j++) printf("%5d",sparse[i][j]); printf("\n"); } }/*End of main()*/
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
Advertise Here
|