Vivekananda College of Engineering and Technology
Department of Electronics & Communication Engineering
Back to Experiments
Experiment 13
C Programming Lab
Aim
To perform matrix multiplication.
Algorithm
1. Read matrices. 2. Multiply using nested loops.
Use or Edit the given C template
#include <stdio.h> int main() { int a[5][5], b[5][5], c[5][5] = {0}; int i, j, k, r, c1; printf("Enter order of matrix: "); scanf("%d %d", &r, &c1); printf("Enter matrix A: "); for(i=0;i<r;i++) for(j=0;j<c1;j++) scanf("%d",&a[i][j]); printf("Enter matrix B: "); for(i=0;i<r;i++) for(j=0;j<c1;j++) scanf("%d",&b[i][j]); for(i=0;i<r;i++) for(j=0;j<c1;j++) for(k=0;k<c1;k++) c[i][j] += a[i][k] * b[k][j]; printf("Result:\n"); for(i=0;i<r;i++) { for(j=0;j<c1;j++) printf("%d ", c[i][j]); printf("\n"); } return 0; }
Input data
Compile & Run
Output
Output will appear here after compilation.
C Programming Virtual Lab - Experiment 13