forked from SoumyajitNag18/Hacktoberfest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
76 lines (68 loc) · 1.62 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
void multiply( int a[][100], int b[][100] , int n )
{
int c[100][100] , i , j , k ;
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
for ( k = 0 ; k < n ; k++ )
{
c[i][j] += a[i][k] * b[k][j] ;
}
}
}
printf(" The resultant matrix is : \n");
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
printf( " %d " , c[i][j] );
}
printf( "\n" );
}
}
int main()
{
int n , i , j , a[100][100] , b[100][100] ;
//the first matrix
printf("Enter the order of the matrices : ");
scanf( "%d" , &n );
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
printf(" Enter the element of the first matrix : ");
scanf( "%d" , &a[i][j] );
}
}
printf(" The first matrix is :\n");
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
printf( " %d " , a[i][j] );
}
printf( "\n" );
}
//the second matrix
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
printf(" Enter the element of the second matrix : ");
scanf( "%d" , &b[i][j] );
}
}
printf(" The second matrix is :\n");
for ( i = 0 ; i < n ; i++ )
{
for ( j = 0 ; j < n ; j++ )
{
printf( " %d " , b[i][j] );
}
printf( "\n" );
}
multiply( a , b , n );
return 0;
}