下载

0下载券

加入VIP
  • 专属下载券
  • 上传内容扩展
  • 资料优先审核
  • 免费资料无限下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 稀疏矩阵运算器(Sparse matrix arithmetic unit)

稀疏矩阵运算器(Sparse matrix arithmetic unit).doc

稀疏矩阵运算器(Sparse matrix arithmeti…

厚爱我的你
2018-11-09 0人阅读 举报 0 0 0 暂无简介

简介:本文档为《稀疏矩阵运算器(Sparse matrix arithmetic unit)doc》,可适用于社会民生领域

稀疏矩阵运算器(Sparsematrixarithmeticunit)稀疏矩阵运算器(Sparsematrixarithmeticunit)#includesstdioh><#includesmalloch><#includesstdlibh><#definemaxsize假设非零元素个数的最大值为#definemaxrc假设矩阵的最大行数为typedefintelemtypetypedefstruct{inti,j非零元的行下标和列下标elemtypeand非零元的值}triplestypedefstruct{tripledate(maxsizeintrposmaxrc各行第一个非零元在三元组的位置表inths,ls,fls}tsmatrix,*matrixvoidcreat(tsmatrixm){inti,kfor(i=,the<=maxrci)mrposi=printf("请输入矩阵的行数、列数和非零元个数(以空格隔开):")scanf("ddd",mhs,mls,mfls)for(i=,the<=mflsi){printf("请用三元组形式输入矩阵的元素(行列非零元素):")scanf("ddd",mdata,mdataj,mdatai))}for(i=,k=,the<=mhsi){mrposi=kwhile(mdatak<=k<=mfls)k}}voidxiangjia(tsmatrix,tsmatrixb,tsmatrixc,intn){inta,b,s,lchs=ahscls=alsa=b=l=while(<=aflsb<=bfls){if(adata==bdatab){if(adataaj<bdatabj)cdatal=adataelseif(adataaj>bdatabj){cdatal=bdatabcdataland=n*bdatab)}else{temp=adataaandbn*bdataandif(temp){cdatal=adataacdataland=templ}ab}}elseif(adata<bdatab)cdatal=adataelse{cdatal=bdatabcdataland=n*bdatab)}}while(<=afls)cdatal=adatawhile(b<=bfls){cdatal=bdatabcdataland=n*bdatab)}cfls=l}intxiangcheng(tsmatrix,tsmatrixb,tsmatrixq){intarow,brow,ccol,tp,p,q,tintctempmaxrcif(als!=bhs)returnqhs=ahsqls=blsqfls=if(afls*bfls){for(arow=arow<=ahsarow){for(ccol=ccol<=qlsccol)ctempccol=qrposarow=qflsif(arow<ahs)tp=arposarowelsetp=aflsfor(p=arposarowp<tp,p){brow=adatapjif(browbhs)t=brposbrowelset=bflsfor(q=brpos(brow)q<t,q){ccol=bdataqjctempccol=adatapandqand*bdata}}for(ccol=ccol<=qlsccol){if(ctempccol){if(qfls>maxsize)returnqdataqfls=arowqdataqflsj=ccolqdataqflsand=ctempccol}}}}return}voidprintsmatrix(tsmatrixm){intk,l,nthematrixpp=amfor(k=,n=k<=p>hsk){for(l=l<=p>lsl){if(p>daten=kp>datenj==){printf("d",p>datenand)n}elseprintf("d',)}printf("n")}printf("n")}voidzhuanzhi(tsmatrix*,tsmatrix*b){intqwithpb>hs=a>lsb>ls=a>hsb>fls=a>flsif(b>fls){q=for(with=with<=>lsthe)for(p=)p<=a>flsp)if(>datepj==on){b>dateq=>datepjb>dateqj=a>datepb>dateqand=a>datepandq}}}voiddestorysmatrix(tsmatrixm){mhs=mls=mfls=}voidmain(){tsmatrixa,b,ctsmatrix*p=,*q=bintflag,nwhile(){system("cls")printf("nnn")printf("tn")printf("t***稀疏矩阵的加、减、转、乘***n")printf("tn")printf("t、稀疏矩阵的加法n")printf("t、稀疏矩阵的减法n")printf("t、稀疏矩阵的转置n")printf("t、稀疏矩阵的乘法n")printf("t、退出该应用程序n")printf("tn")printf("输入要进行的项目的编号:")scanf("d",flag)if(flag==)breakcreat(a)printf("矩阵a:n")printsmatrix(a)switch(flag){case:creat(b)n=printf("矩阵b:n")printsmatrix(b)if(ahs==bhsals==bls){printf("ab:n")xiangjia(a,b,c,n)printsmatrix(c)}elseprintf("错误!行列不一致n")breakcase:creat(b)n=printf("矩阵b:n")printsmatrix(b)if(ahs==bhsals==bls){printf("ab:n")xiangjia(a,b,c,n)printsmatrix(c)}elseprintf("错误!行列不一致n")breakcase:printf("a>b:n")zhuanzhi(p,q)printsmatrix(B)打破案例:Creat(b)printf(“矩阵B:n”)printsmatrix(B)printf(“A×B:n”)n=襄城(abc)如果(~n)printf(“错误~行列不匹配n”)其他printsmatrix(C)打破默认值:printf(“输入错误~“n)}destorysmatrix(一)destorysmatrix(B)destorysmatrix(C)getchar()getchar()}printf(“nTTT*程序已经退出***n”)getchar()}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

评分:

/10

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利