小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

113.實矩陣乘法運算

 C語言與CPP編程 2022-05-05 發(fā)布于安徽
#include "stdio.h"
#define MAX 255
void MatrixMul(a,b,m,n,k,c)  /*實矩陣相乘*/
int m,n,k; /*m:矩陣A的行數, n:矩陣B的行數, k:矩陣B的列數*/
double a[],b[],c[]; /*a為A矩陣, b為B矩陣, c為結果,即c = AB */
{
	int i,j,l,u;
	/*逐行逐列計算乘積*/
	for (i=0; i<=m-1; i++)
		for (j=0; j<=k-1; j++)
		{
			u=i*k+j; c[u]=0.0;
			for (l=0; l<=n-1; l++)
				c[u]=c[u]+a[i*n+l]*b[l*k+j];
		}
	return;
}



main()
{
	int i,j,m,n,k;
	double A[MAX];
	double B[MAX];
	double C[MAX];
	for(i=0;i<MAX;i++)
		C[i]=1.0;
	clrscr();
	puts("This is a real-matrix-multiplication program.\n");
	puts("It calculate the two matrixes C(m*k)=A(m*n)B(n*k).\n");
	printf(" >> Please input the number of rows in A, m= ");
	scanf("%d",&m);
	printf(" >> Please input the number of cols in A, n= ");
	scanf("%d",&n);
	printf(" >> Please input the number of cols in B, k= ");
	scanf("%d",&k);
	printf(" >> Please input the %d elements in A one by one:\n",m*n);
	for(i=0;i<m*n;i++)
		scanf("%lf",&A[i]);
	printf(" >> Please input the %d elements in B one by one:\n",n*k);
	for(i=0;i<n*k;i++)
		scanf("%lf",&B[i]);

	MatrixMul(A,B,m,n,k,C); /*計算C的結果*/
	/*格式化輸出結果*/
	printf("\n >> The result of C(%d*%d)=A(%d*%d)B(%d*%d) is:\n",m,k,m,n,n,k);
	for (i=0; i<m; i++)
	{
		for (j=0; j<k; j++)
			printf("%10.5f    ",C[i*k+j]);
		printf("\n");
	}
	printf("\n Press any key to quit...\n");
	getch();
	return 0;
}

    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多