TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Matrix multiplication in C

Matrix multiplication in C with programming examples for beginners and professionals covering concepts, control statements, c array, c pointers, c structures, c union, c strings and more.

<< Back to MATRIX

Matrix multiplication in C

Matrix multiplication in C: We can add, subtract, multiply and divide 2 matrices. To do so, we are taking input from the user for row number, column number, first matrix elements and second matrix elements. Then we are performing multiplication on the matrices entered by the user.

In matrix multiplication first matrix one row element is multiplied by second matrix all column elements.

Let's try to understand the matrix multiplication of 2*2 and 3*3 matrices by the figure given below:

matrix multiplication program in c

Let's see the program of matrix multiplication in C.

#include<stdio.h>  
#include<stdlib.h>
int main(){
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;  
system("cls");
printf("enter the number of row=");  
scanf("%d",&r);  
printf("enter the number of column=");  
scanf("%d",&c);  
printf("enter the first matrix element=\n");  
for(i=0;i<r;i++)  
{  
for(j=0;j<c;j++)  
{  
scanf("%d",&a[i][j]);  
}  
}  
printf("enter the second matrix element=\n");  
for(i=0;i<r;i++)  
{  
for(j=0;j<c;j++)  
{  
scanf("%d",&b[i][j]);  
}  
}  
  
printf("multiply of the matrix=\n");  
for(i=0;i<r;i++)  
{  
for(j=0;j<c;j++)  
{  
mul[i][j]=0;  
for(k=0;k<c;k++)  
{  
mul[i][j]+=a[i][k]*b[k][j];  
}  
}  
}  
//for printing result  
for(i=0;i<r;i++)  
{  
for(j=0;j<c;j++)  
{  
printf("%d\t",mul[i][j]);  
}  
printf("\n");  
}  
return 0;
}

Output:

enter the number of row=3
enter the number of column=3
enter the first matrix element=
1 1 1
2 2 2
3 3 3
enter the second matrix element=
1 1 1
2 2 2
3 3 3
multiply of the matrix=
6 6 6
12 12 12
18 18 18

Let's try to understand the matrix multiplication of 3*3 and 3*3 matrices by the figure given below:

matrix multiplication in c


Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf