数据结构之矩阵的乘法运算

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengshijian2015/article/details/52649554
#define TRUE 1
#define OK 1
#define ERROR 0
#define FASE 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define MAXSIZE 100

#include<stdlib.h>

int **calculateMatrix(int a[][2], int b[][2], int n)
{
    int i, j,k;
    int **c=(int **)malloc(n*sizeof(int *));
    for ( i = 0; i < n; i++)
    {
        c[i] = (int *)malloc(n * sizeof(int));
        for (j = 0; j < n; j++)
        {

            c[i][j] = 0;
            for (k = 0; k < n; k++)
            {
                c[i][j]+=a[i][k] + b[k][j];
            }
        }
    }
    return c;
}


int main()
{
    int a[2][2] = {
        {1,2},{3,4}
    };
    int **c;
    int b[2][2] = {
        { 1,2 },{ 3,4 }
    };
    c=calculateMatrix(a,b, 2);
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            printf("%d ", c[i][j]);
        }
        printf("\n");
    }
    return 0;
}
展开阅读全文

没有更多推荐了,返回首页