Initialising a Two Dimensional Array - Arrays C Program
C Program to illustrate Matrix Multiplication
* Program for matrix multiplication */
#include <stdio.h>
main()
{
int a[5][5], b[5][5],c[5][5],r1, r2, c1, c2, i,j,k;
Step 1 :
printf("\nEnter the size of the matrix A....");
scanf("%d %d", &rl, & cl);
printf("\nEnter the size of the matrix B....");
scanf("%d %d", &r2, & c2);
if(c1= =r2)
goto step2;
else
printf("\nMultiplication is not possible");
goto stepl;
Step2 :
printf("\nEnter matrix A elements...\n");
for(i=0;i<r1;i++)
{
for(j=0;j<cl;j++)
scanf("%d", &a[i][j]);
} /* for */
printf("\nEnter matrix B elements...\n");
for(i=0;i<r2;i++)
{
scanf("%d", &b[i][j]);
} /* for */
for(i=0;i<rl;i++)
{
for(j=0;j<c1;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
} /* for */
printf("\nThe resultant matrix is ....\n");
for(i=0;i<rl;i++)
for(j=0;j<c1;j++)
printf("%d\t",c[i][j]);
printf("\n");
} /* for */
} /* main */
OUTPUT:
Enter the size of the matrix A....3 3
Enter the size of the matrix B....2 2
Multiplication is not possible
Enter the size of the matrix A....3 3
Enter the size of the matrix B....3 3
Enter matrix A elements...
2 2 2 2 2 2 2 2 2
Enter matrix B elements...
3 3 3 3 3 3 3 3 3
The resultant matrix is
18 18 18
18 18 18
18 18 18
EXPLANATION: The program reads size of the matrix, then checks rows and column are equal or not. If rows and columns are equal further execution starts, else it prints multiplication is not possible. The i and j for loop is used to get both A and B matrix. The another i and j for loop is used to calculate the matrix multiplication and final i and j for loop is used to print the resultant matrix.
Computer Programming C Laboratory: Arrays C Programs : Tag: C Programming : - C Program to illustrate Matrix Multiplication (Two Dimensional Array)
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation