Processing & Properties of Floor and Wall Tiles.pptx
Cse 121 presentation on matrix [autosaved]
1. Presentation on Matrix
Course Name: Structured Programming
Course Code: CSE 121
Presented By :
Mahmuda Akter Kanis Fatema
Roll: 17102009 Roll: 17102010 st
1st year 2ndnd semester , Computer Science & Engineering ,
JKKNIU
2. Topics
• Definition of matrix
• Kinds of matrix
• Addition of Matrix
• Multiplication of matrix
3.
4.
5.
6.
7.
8.
9.
10.
11. Code of matrix addition:
#include <stdio.h>
int main()
{
int m, n, c, d, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of matrixn");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrixn");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
printf("Enter the elements of second matrixn");
12. for (c = 0; c < m; c++)
for (d = 0 ; d < n; d++)
scanf("%d", &second[c][d]);
printf("Sum of entered matrices:-n");
for (c = 0; c < m; c++) {
for (d = 0 ; d < n; d++) {
sum[c][d] = first[c][d] + second[c][d];
printf("%dt", sum[c][d]);
}
printf("n");
}
return 0;
}
14. Multiplication of Matrix :.
Condition : If an only if ,
the number of columns in the first matrix = the number of rows
in second matrix
Then it is possible to multiply.
15. Matrix Multiplication Algorithm :
Step 1 :Start
Step 2 : Declare variables and initialize necessary variables
Step 3 : Enter the element of matrices by row wise using
loops
Step 4 : Check the number of rows and column of first and
second matrices . If number of rows of first matrix is equal
to the number of columns of second matrix, go to step 6.
Otherwise, print matrix multiplication is not possible and go
to step 3.
Step 5 : Multiply the matrices using nested loops.
Step 6 : Print the product in matrix form as console output.
Step 7 : Stop.
16. Code of matrices multiplication:
#include <stdio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("Enter the number of rows and columns of first matrixn");
scanf("%d%d", &m, &n);
printf("Enter the elements of first matrixn");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
printf("Enter the number of rows and columns of second matrixn");
scanf("%d%d", &p, &q);
17. if (n != p)
printf("Matrices with entered orders can't be multiplied with each other.n");
else
{
printf("Enter the elements of second matrixn");
for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++) {
for (k = 0; k < p; k++) {
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
printf("Product of entered matrices:-n");
18. for (c = 0; c < m; c++) {
for (d = 0; d < q; d++)
printf("%dt", multiply[c][d]);
printf("n");
}
}
return 0;
}
Output:
19. So, we learn about
• Definition of matrix
• Kinds of matrix
• Addition of Matrices
• Multiplication of matrices
THANKS All