2D Array pdf
2D Array pdf
Multiplication
Two-Dimensional (2D) Arrays in C
Where ,
#include<stdio.h>
int main ( ) {
output :
int arr [3] [2] = { { 0 , 1 } , { 2 , 3} , { 4 , 5 } } ; arr [ 0 ] [ 0 ] : 0
for ( int i = 0 ; i < 3 ; i++) { arr [ 0 ] [ 1 ] : 1
for ( int j = 0 ; j < 2 ; j++) { arr [ 2 ] [ 0 ] : 2
printf (“arr[ %d] [%d] : %d “, i , j , arr [ i ] [ j ] ) ; arr [ 1 ] [ 1 ] : 3
} arr [ 2 ] [ 0 ] : 4
printf (“\n”) ; arr [ 2 ] [ 1 ] : 5
}
return 0;
}
MATRIX
MULTIPLICATION
Matrix Multiplication in C
A matrix is a collection of numbers
organized in rows and columns,
represented by a two-dimensional
array in C. Matrices can either be
square or rectangular. In this article,
we will learn the multiplication of two
matrices in the C programming
language.
Example :
❖Input :
mat[ ] [ ] = { { 1 , 2 },
{3,4}}
mat[ ] [ ] = { { 5 , 6 }
{7,8}
{ { 19 , 22 } ,
{ 43 , 50 } }
Example : #include <stdio.h>
int main() {
int A[2][2], B[2][2], C[2][2]
int i, j, k;
printf("Enter elements of 2x2 Matrix A:\n");
for(i = 0; i < 2; i++) {
for(j = 0; j < 2; j++) {
printf("A[%d][%d]: ", i, j);
scanf("%d", &A[i][j]);
}
}
printf("Enter elements of 2x2 Matrix B:\n");
for(i = 0; i < 2; i++) {
for(j = 0; j < 2; j++) {
printf("B[%d][%d]: ", i, j);
scanf("%d", &B[i][j]);
}
}
For ( i = 0 ; i < 2 ; i++ ) {
for ( j = 0 ; j < 2 ; j++) { INPUT :
C[i][j]=0; Matrix A : 1 2
for ( k = 0 ; k < 2 ; k++ ) { 3 4
C [ i ] [ j ] += A [ i ] [ k ] * B [ k ] [ j ] ; Matrix B : 5 6
} 7 8
}
}
printf ( “ Resultant Matrix ( A × B ) : \n “ ) ; OUTPUT :
for ( i = 0 ; i < 2 ; i++ ) { Resultant Matrix ( A * B ) :
for ( j = 0 ; j < 2 ; j++ ) { 19 22
printf ( “ %d \ t “ , C [ i ] [ j ] ) ; 43 50
}
printf ( “ \n “ ) ;
}
return 0 ;
}
THANK
YOU