top of page

A C+ program that will Multiply two matrices

  • Writer: Nelson John
    Nelson John
  • Nov 22, 2017
  • 2 min read

include<stdio.h>

int main() {

int a[10][10], b[10][10], c[10][10], i, j, k;

int sum = 0;

printf("\nEnter First Matrix : ");

for (i = 0; i < 3; i++) {

for (j = 0; j < 3; j++) {

scanf("%d", &a[i][j]);

}

}

printf("\nEnter Second Matrix:n");

for (i = 0; i < 3; i++) {

for (j = 0; j < 3; j++) {

scanf("%d", &b[i][j]);

}

}

printf("The First Matrix is: \n");

for (i = 0; i < 3; i++) {

for (j = 0; j < 3; j++) {

printf(" %d ", a[i][j]);

}

printf("\n");

}

printf("The Second Matrix is : \n");

for (i = 0; i < 3; i++) {

for (j = 0; j < 3; j++) {

printf(" %d ", b[i][j]);

}

printf("\n");

}

//Multiplication Logic

for (i = 0; i <= 2; i++) {

for (j = 0; j <= 2; j++) {

sum = 0;

for (k = 0; k <= 2; k++) {

sum = sum + a[i][k] * b[k][j];

}

c[i][j] = sum;

}

}

printf("\nMultiplication Of Two Matrices : \n");

for (i = 0; i < 3; i++) {

for (j = 0; j < 3; j++) {

printf(" %d ", c[i][j]);

}

printf("\n");

}

return (0);

}

This is what the output will look like

Enter First Matrix : 1 1 1 1 1 1 1 1 1

Enter Second Matrix: 1 1 1 1 1 1 1 1 1

The First Matrix is:

1 1 1

1 1 1

1 1 1

The Second Matrix is:

1 1 1

1 1 1

1 1 1

Multiplication Of Two Matrices :

3 3 3

3 3 3

3 3 3

Facebook: ayamnelrodinho1@gmail.com

Yahoo: talk2nelsonjohn2dat@yahoo.com

Whatsapp: +2349034595610

PLEASE KINDLY SHARE WITH FELLOW PROGRAMMERS AND ALSO SUBSCRIBE TO MY BLOG FROM THE HOME PAGE FOR MORE FEEDS.


 
 
 

Comments


bottom of page