File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+
3
+ int main (void )
4
+ {
5
+ void scalarMultiply (int matrix [3 ][5 ], int scalar );
6
+ void displayMatrix (int matrix [3 ][5 ]);
7
+ int sampleMatrix [3 ][5 ] =
8
+ {
9
+ { 7 , 16 , 55 , 13 , 12 },
10
+ { 12 , 10 , 52 , 0 , 7 },
11
+ { -2 , 1 , 2 , 4 , 9 }
12
+ };
13
+
14
+ printf ("Original matrix:\n" );
15
+ displayMatrix (sampleMatrix );
16
+
17
+ scalarMultiply (sampleMatrix , 2 );
18
+
19
+ printf ("\nMultiplied by 2:\n" );
20
+ displayMatrix (sampleMatrix );
21
+
22
+ scalarMultiply (sampleMatrix , -1 );
23
+
24
+ printf ("\nThen multiplied by -1:\n" );
25
+ displayMatrix (sampleMatrix );
26
+
27
+ return 0 ;
28
+ }
29
+
30
+ // Function to multiply a 3 x 5 array by a scalar
31
+
32
+ void scalarMultiply (int matrix [3 ][5 ], int scalar )
33
+ {
34
+ int row , column ;
35
+
36
+ for ( row = 0 ; row < 3 ; ++ row )
37
+ for ( column = 0 ; column < 5 ; ++ column )
38
+ matrix [row ][column ] *= scalar ;
39
+ }
40
+
41
+ void displayMatrix (int matrix [3 ][5 ])
42
+ {
43
+ int row , column ;
44
+
45
+ for ( row = 0 ; row < 3 ; ++ row ) {
46
+ for ( column = 0 ; column < 5 ; ++ column )
47
+ printf ("%5i" , matrix [row ][column ]);
48
+ printf ("\n" );
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments