产生A(5行4列),B(4行3列)两个随机矩阵,每个元素是[-10,10]之间的随机整数并打印出来,打印出它们的乘积C矩阵。要求矩阵用*******分隔开,以A,B,C的顺序打印,各行对齐。
#include "stdafx.h"
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <time.h>
#pragma warning(disable: 4996)
#define X 5
#define Y 4
#define Z 3
int c[X][Y];
int b[Y][Z];
int a[X][Z];
int main()
{
int i, j;
system("cls");
srand(time(NULL));
for (i = 0; i<X; i++)
for (j = 0; j<Y; j++){
b[i][j] = rand() % 20-10;
}
srand(time(NULL));
for (i = 0; i<Y; i++)
for (j = 0; j<Z; j++){
a[i][j] = rand() % 20-10;
}
printf("***************************************");
for (i = 0; i<X; i++){
printf("\n");
for (j = 0; j<Y; j++)
printf("%5d ", b[i][j]);
}
int k;
for (i = 0; i<5; i++)
for (j = 0; j<4; j++)
for (k = 0; k<3; k++)
{ c[i][k] += b[i][j] * a[j][k];
}
printf("\n");
printf("***************************************");
for (i = 0; i<Y; i++){
printf("\n");
for (j = 0; j<Z; j++)
printf("%5d ", c[i][j]);
}
printf("\n");
printf("****************************************");
for (i = 0; i<X; i++){
printf("\n");
for (j = 0; j<Z; j++)
printf("%5d ", c[i][j]);
}
getch();
return 0;
}