Skip to main content

Static Matrix Multiplication

// Matrix Multiplication

#include<stdio.h>
int main()
{
    int a[3][3],b[3][3],c[3][3],d[3][3];
    int i,j,k;

        printf("Enter Elements of Matrix - A\n");
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                printf("a[%d][%d] : ",i,j);
                scanf("%d",&a[i][j]);
            }
        }
        printf("Enter Elements of Matrix - B \n");
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                printf("b[%d][%d] : ",i,j);
                scanf("%d",&b[i][j]);
            }
        }

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

        printf("\nMatrix - A\n");
        for(i=0;i<3;i++)
        {
        printf("|");
            for(j=0;j<3;j++)
            {
                printf("%3d",a[i][j]);
            }
            printf(" | \n");
        }

        printf("\nMatrix - B\n");
        for(i=0;i<3;i++)
        {
        printf("|");
            for(j=0;j<3;j++)
            {
                printf("%3d",b[i][j]);
            }
            printf(" | \n");
        }

        printf("\nMatrix Multiplication - A*B\n");
        for(i=0;i<3;i++)
        {
        printf("|");
            for(j=0;j<3;j++)
            {
                printf("%3d",c[i][j]);
            }
            printf(" | \n");
        }

        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                d[i][j] = 0;
                for(k=0;k<3;k++)
                {
                    d[i][j] += b[i][k]*a[k][j];
                }
            }
        }

        printf("\nMatrix Multiplication - B*A\n");
        for(i=0;i<3;i++)
        {
        printf("|");
            for(j=0;j<3;j++)
            {
                printf("%3d",d[i][j]);
            }
            printf(" | \n");
        }
}



Comments

Popular posts from this blog

Dynamic Matrix Multiplication

// Matrix Multiplication #include<stdio.h> #define SIZE 5 int main() {     int a[SIZE][SIZE],b[SIZE][SIZE],c[SIZE][SIZE],d[SIZE][SIZE];     int i,j,k,r1,r2,c1,c2;     printf("Enter the Rows of Matrix - A : ");     scanf("%d",&r1);     printf("Enter the Columns of Matrix - A : ");     scanf("%d",&c1);     printf("Enter the Rows of Matrix - B : ");     scanf("%d",&r2);     printf("Enter the Columns of Matrix - B : ");     scanf("%d",&c2);     if(c1 == r2)     {         printf("Enter Elements of Matrix - A\n");         for(i=0;i<r1;i++)         {             for(j=0;j<c1;j++)             {                 printf("a[%d][%d] : ",i,j);       ...

Simple Matrix

// Simple Matrix Upto n Numbers. (Dynamic) #include<stdio.h> int main() {     int i,j,k=1,rc;     printf("Enter the No of Columns : ");     scanf("%d",&rc);     for(i=0;i<rc;i++)     {          printf("|");         for(j=0;j<rc;j++,k++)         {             printf("%3d",k);         }         printf(" | \n");     }     return 0; }