CH4_1.C
上传用户:lgb298
上传日期:2013-03-22
资源大小:1025k
文件大小:1k
- #include <stdio.h>
- #define N 9
- typedef struct node
- { int i,j,v;
- }JD;
- int trans_sparmat(JD ma[],JD mb[])
- { int col,p,n,t,k;
- if(ma[0].v==0)
- return(0);
- n=ma[0].j;
- t=ma[0].v;
- mb[0].i=n; mb[0].j=ma[0].i; mb[0].v=t;
- k=1;
- for(col=1;col<=n;col++)
- for(p=1;p<=t;p++)
- if(ma[p].j==col)
- { mb[k].i=ma[p].j;
- mb[k].j=ma[p].i;
- mb[k].v=ma[p].v;
- k++;
- }
- return(1);
- }
- void main()
- { JD ma[N]={{6,7,8},{1,2,12},{1,3,9},{3,1,-3},
- {3,6,14},{4,3,24},{5,2,18},{6,1,15},{6,4,-7}};
- JD mb[N];
- int i;
- trans_sparmat(ma,mb);
- for(i=0;i<N;i++)
- printf("%d,%d,%dn",mb[i].i,mb[i].j,mb[i].v);
- }