当前位置:17727 > 17727.com > 求矩阵乘积出错,不知道哪里有错

求矩阵乘积出错,不知道哪里有错

文章作者:17727.com 上传时间:2019-12-28

17727.com 1

#define_CRT_SECURE_NO_WARNINGS#includestdio.h#includemath.h#definem2int*ab(inta[m][m],intb[m][m]){inttemp[m][m]={0},sum=0;for(inti=0;im;i++){for(intj=0;jm;j++){sum=0;for(intk=0;km;k++){sum=sum+a[i][k]*b[k][j];}temp[i][j]=sum;}}returntemp;}voidmain(){unsignedinto;inta[m][m],b[m][m];printf("输入数组an");for(inti=0;im;i++){for(intj=0;jm;j++){scanf("%d",a[i][j]);}}printf("输入数组bn");for(inti=0;im;i++){for(intj=0;jm;j++){scanf("%d",b[i][j]);}}int*res;res=ab(a,b);for(inti=0;im;i++){for(intj=0;jm;j++){printf("%d",*(res+i*m+j));}printf("n");}}

各位大佬看看哪出错了#includestdio.h/*函数fun功能是:将二维数组的第k行的元素依次与第0行元素交换123456789当k的值为2,变换为789456123*/voidfun(ints[][3],intk){inttemp,j=2;inti;for(i=0;ik;i++){temp=s[i][2];s[i][2]=s[j][2];s[j][2]=temp;j--;}}intmain(){intk;intn=3,m=3;scanf("%d",k);inta[n][m];for(inti=0;in;i++)for(intj=0;jm;j++)scanf("%d",a[i][j]);for(inti=0;in;i++)for(intj=0;jm;j++)printf("%d",a[i][j]);fun(a,k);return0;}

17727.com 2

//求销售利润并排序#includestdio.hinta[5][5];intarrays(inta[5][5]);intfunction(intb[4]);intmain(void){inti,j,result;printf("pleaseinputtheprinceofthethoseproducts.n");//输入单价for(j=0;j5;j++){printf("project%in",j+1);scanf("%i",a[0][j]);}printf("pleaseinputthesalesvolumeofeveryone.n");//输入销售量for(i=1;i5;i++){for(j=0;j5;j++){scanf("%in",a[i][j]);}}arrays(a);//引用函数比较计算}intarrays(inta[5][5])//比较函数{inti,j;inttemp;intb[4],c[5];for(i=1;i5;i++){temp=0;for(j=0;j5;j++){temp=temp+a[0][j]*a[i][j];}printf("销售员%i的销售量是%in",i,temp);c[i]=temp;}for(i=0;i4;i++)b[i]=c[i]/10;function(b);}intfunction(intb[4])//排序函数。{inti,j,k;inttemp;intc[4];for(i=0;i4;i++)c[i]=b[i];for(j=4;j0;j--){for(i=0;ij;i++){if(c[i]c[i+1]){temp=c[i];c[i]=c[i+1];c[i+1]=temp;}}}for(k=0;k4;k++){printf("%in",c[k]);}}

题目如下:代码如下:#includeiostream#includestdlib.h#includevectorusingnamespacestd;vectorintveca;vectorintvecb;inta[1001];intb[1001];intmyarr[2002];intsums=0;//ab数组之和intdt_sum=0;//|sum(a)-sum(b)|intcounts=0;inttemparr[2002];//用与记录结果intInput(){intj=0,ta=0,tb=0;do{scanf("%d",j);veca.push_back(j);ta++;}while(cin.get()!='n');do{scanf("%d",j);vecb.push_back(j);tb++;}while(cin.get()!='n');for(inti=0;ita;i++){a[i]=veca.at(i);b[i]=vecb.at(i);}returnta;}voidSwapArr(intindex,intsum,intlen){if(counts=len){inttemp_dt_sum=abs(sums-2*sum);if(temp_dt_sumdt_sum){dt_sum=temp_17727.com,dt_sum;}return;}for(inti=index;i2*len;i++){sum=sum+myarr[i];temparr[counts]=myarr[i];counts++;//元素计数SwapArr(i+1,sum,len);temparr[counts]=0;counts--;sum=sum-myarr[i];}}intmain(){intn,len;inta_sum=0,b_sum=0;cinn;while(n--){a_sum=0;b_sum=0;len=Input();for(inti=0;ilen;i++){myarr[i]=a[i];myarr[i+len]=b[i];a_sum=a_sum+a[i];b_sum=b_sum+b[i];}/*dt_sum=|sum(a)-sum(b)|*/dt_sum=abs(a_sum-b_sum);sums=a_sum+b_sum;SwapArr(0,0,len);printf("%dn",dt_sum);}return0;}

本文由17727发布于17727.com,转载请注明出处:求矩阵乘积出错,不知道哪里有错

关键词: