三元组表稀疏矩阵其求和.docVIP

  • 0
  • 0
  • 约5.46千字
  • 约 6页
  • 2019-11-11 发布于广东
  • 举报
#include stdio.h #define MAXSIZE 100 struct node { int i,j; int v; }; struct sparmatrix { int rows,cols; int terms; struct node data[MAXSIZE]; }; void sum(struct sparmatrix a,struct sparmatrix b); main() { int m[MAXSIZE][MAXSIZE],n[MAXSIZE][MAXSIZE]; int i,j,mrow,mcol,nrow,ncol,ano=0,bno=0,counter=0,t=0; struct sparmatrix a,b; printf(Please input row and col of matrix m(for example: row,col):); scanf(%d,%d,mrow,mcol); printf(\n); printf(Please input row and col of matrix n(for example: row,col):); scanf(%d,%d,nrow,ncol); if ((mrow!=nrow)||(mcol!=ncol)) { printf(ERROR: dimensions of m,n are different!); getch(); return; /*comapre dimension between matrix m and n*/ } for (i=0;imrow;i++) for (j=0;jmcol;j++) { printf(input value of data element m[%d][%d] ,i,j); scanf(%d,m[i][j]); } /*input value of matrix m*/ for (i=0;inrow;i++) for (j=0;jncol;j++) { printf(input value of data element n[%d][%d] ,i,j); scanf(%d,n[i][j]); } /*input value of matrix n*/ printf(matrix m you input as follows:\n); for (i=0;imrow;i++) for (j=0;jmcol;j++) { if (t==mcol) { printf(\n); t=0; } printf( %d,m[i][j]); t++; } /*output matrix m*/ printf(\n); printf(\n); printf(matrix n you input as follows:\n); t=0; for (i=0;inrow;i++) for (j=0;jncol;j++) { if (t==ncol) { printf(\n); t=0; } printf( %d,n[i][j]); t++; } /*output matrix n*/ printf(\n); printf(\n); for (i=0;imrow;i++) for (j=0;jmcol;j++) if (m[i][j]!=0) { counter++; a.data[ano].i=i; a.data[ano].j=j; a.data[ano].v=m[i][j]; ano++;

文档评论(0)

1亿VIP精品文档

相关文档