0% found this document useful (0 votes)
27 views5 pages

CPL Program 6

The document outlines a program for 2D array manipulation, specifically focusing on matrix multiplication while ensuring compatibility rules are checked. It includes an algorithm, test cases for different matrix orders, and a sample C program that implements the multiplication. Additionally, it lists viva and modification questions related to matrix operations.

Uploaded by

sn0385313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views5 pages

CPL Program 6

The document outlines a program for 2D array manipulation, specifically focusing on matrix multiplication while ensuring compatibility rules are checked. It includes an algorithm, test cases for different matrix orders, and a sample C program that implements the multiplication. Additionally, it lists viva and modification questions related to matrix operations.

Uploaded by

sn0385313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Develop a program to introduce 2D Array manipulation and implement Matrix multiplication and

ensure the rules of multiplication are checked.

Algorithm:
Step 1: Start
Step 2: Read the order of two matrices A and B
Step 3: Check the number of rows and column of A and B matrices for compatibility
Step 4: Read two matrices A and B
Step 5: For i from 0 to m:
For j from 0 to q:
a. Let c[i][j] = 0
b. For k from 1 to n:
Set c[i][j] ← c[i][j]+a[i][k]*b[k][j];
Step 6: Display the Matrix A and B. Resultant Matrix C

Step 7: Stop

Test Cases:
Sl. Test Data Expected Output
No. Order of Order of Enter Enter
Matrix A Matrix B Matrix A Matrix B
1 2 2 2 2 1234 1234 Matrix Matrix B: Matrix C:
A: 1 2 7 10
1 2 3 4 15 22
3 4
2 3 2 2 2 123321 1231 Matrix Matrix B: Matrix C:
A: 1 2 7 4
1 2 3 1 12 9
3 3 5 5
2 1
3 2 4 1 2 Matrices are Incompatible

Viva Questions:

Sl. No Questions
1. What is matrix?
2. What is one dimensional array?
3. Write the Syntax for one dimensional array.
4. What is two dimensional array?
5. Write the Syntax for two dimensional array.

Modification Questions:

Sl.NO Questions
1. Develop a program to introduce 2D Array manipulation and implement matrix
addition.
2. Develop a program to introduce 2D Array manipulation and implement matrix
Subtraction
3. Develop a program to introduce 2D Array manipulation and implement matrix
transpose.
Flowchart:

START

Read m,n,p,q

T Print Multiplication
not allowed
If(n!=p
)
F
B
For(i=0;i<m;i++)

For(j=0;j<n;j++)

Read A[i][j]

F
For(i=0;i<p;i++)

For(j=0;i<q;j++)

T A
Read B[i][j]
A
F

For(i=0;i<m;i++
)
F

For(j=0;j<q;j++)

C[i][j]=0
F

For(k=0;j<n;k+
+)
F
C[i][j]=C[i][j]+A[i][k]*B[k][j]

For(i=0;i<n;i++)

F T
F
For(j=0;j<n;j++)

Print C[i][j]

B
STOP
Program:
#include<stdio.h>
void main()
{
int i,j,k,a[10][10],b[10][10],c[10][10],m,n,p,q;
printf("Enter the order of matrix A:\n");
scanf("%d%d",&r1,&c1);
printf("Enter the order of matrix B:\n");
scanf("%d%d",&r2,&c2);

if (c1==r2)
{
printf("Enter Matrix A\n");
for (i=0;i<r1;i++)
for (j=0;j<c1;j++)
scanf("%d",&a[i][j]);

printf("Enter Matrix B\n");


for (i=0;i<r2;i++)
for (j=0;j<c2;j++)
scanf("%d",&b[i][j]);

//matrix multiplication
for (i=0;i<r1;i++)
{
for (j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
printf("Matrix A:\n");
for (i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
printf("Matrix B:\n");
for (i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",b[i][j]);
printf("\n");
}
printf("Matrix C:\n");
for (i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
else
printf("Matrices are Incompatible\n");
getch();
}

You might also like