20 November 2010

C Program–Multiplying two matrices

/* Program to multiply two matrices */

#include <stdio.h>
#include <conio.h>
int main()
{
    int a[2][3],b[3][2],c[2][2],k,j,i;
    printf("enter a");
    for(i=0;i<2;i++)   //Get array A
    {
    for(j=0;j<3;j++)
    {
    scanf("%d",&a[i][j]); 
    }
    }
    printf("enter b");
    for(i=0;i<3;i++) //Get array B
    {
    for(j=0;j<2;j++)
    {
    scanf("%d",&b[i][j]);
    }
    }


    for(i=0;i<2;i++) 
    {
    for(j=0;j<2;j++)
    {
    c[i][j]=0;  //to Hold a temporary multiplication
    for(k=0;k<3;k++)
    {
    c[i][j]=c[i][j]+a[i][k]*b[k][j];   //Multiplication algorithm
    }
    }
    }
    printf("C is ");
    for(i=0;i<2;i++)
    for(j=0;j<2;j++)
    printf(" c[%d][%d] - %d \n",i,j,c[i][j]); 
 
getch();  
    return 0;
}

arraymul


0 comments:

Post a Comment

Powered by Blogger.

About Me

Featured Post

5G Network Simulation in NS3 using mmWave | NS3 Tutorial 2024

5G Network Simulation in NS3 Using mmWave This post shows the installation of ns3mmwave in Ubuntu 24.04 and simulates 5G networks in ns3. In...

Contact form

Name

Email *

Message *

Total Pageviews

Search This Blog

Pages

Pages

Pages - Menu

Most Popular

Popular Posts