#include <stdio.h>
#include <string.h>
#include <math.h>
#define M 2
#define N 3
int main(int argc, char const *argv[])
{
int a[M][N] = { {1, 2, 3}, {4, 5, 6}};
int b[N][M] = { {1, 2}, {3, 4}, {5, 6}};
int re = 0;
int c[M][M] = { {0, 0}, {0, 0}};
for (int i = 0; i < M; ++i)
{
for (int j = 0; j < M; ++j)
{
for (int k = 0; k < N; ++k)
{
c[i][j] += a[i][k] * b[k] [j];
#include <string.h>
#include <math.h>
#define M 2
#define N 3
int main(int argc, char const *argv[])
{
int a[M][N] = { {1, 2, 3}, {4, 5, 6}};
int b[N][M] = { {1, 2}, {3, 4}, {5, 6}};
int re = 0;
int c[M][M] = { {0, 0}, {0, 0}};
for (int i = 0; i < M; ++i)
{
for (int j = 0; j < M; ++j)
{
for (int k = 0; k < N; ++k)
{
c[i][j] += a[i][k] * b[k] [j];

本文展示了一个使用C语言编写的矩阵乘法程序,通过3个嵌套循环实现了两个矩阵的相乘,并输出了结果矩阵。
最低0.47元/天 解锁文章
709

被折叠的 条评论
为什么被折叠?



