IGNOU BCA MCA FOURUM

Would you like to react to this message? Create an account in a few clicks or log in to continue.

Previous Year Question Papers Subject wise Lessons Solved Assignments Download Free E-books


    Matrix Multiplication using C

    avatar
    issac


    Posts : 9
    Join date : 2009-11-13

    Matrix Multiplication using C Empty Matrix Multiplication using C

    Post  issac Fri Nov 13, 2009 7:55 am



    #include <stdio.h>
    #include <conio.h>

    void mult_matrices(int a[][3], int b[][3], int result[][3]);
    void print_matrix(int a[][3]);

    void main(void)
    {
    int p[3][3] = { {1, 3, -4}, {1, 1, -2}, {-1, -2, 5} };
    int q[3][3] = { {8, 3, 0}, {3, 10, 2}, {0, 2, 6} };
    int r[3][3];

    mult_matrices(p, q, r);
    print_matrix(r);
    }

    void mult_matrices(int a[][3], int b[][3], int result[][3])
    {
    int i, j, k;
    for(i=0; i<3; i++)
    {
    for(j=0; j<3; j++)
    {
    for(k=0; k<3; k++)
    {
    result[i][j] = a[i][k] + b[k][j];
    }
    }
    }
    }

    void print_matrix(int a[][3])
    {
    int i, j;
    for (i=0; i<3; i++)
    {
    for (j=0; j<3; j++)
    {
    printf("%d\t", a[i][j]);
    }
    printf("\n");
    }
    }

      Current date/time is Thu Mar 28, 2024 3:08 am