-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprog.8.13.c
50 lines (38 loc) · 977 Bytes
/
prog.8.13.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
#include <stdio.h>
int main (void)
{
void scalarMultiply (int matrix[3][5], int scalar);
void displayMatrix (int matrix[3][5]);
int sampleMatrix[3][5] =
{
{ 7, 16, 55, 13, 12 },
{ 12, 10, 52, 0, 7 },
{ -2, 1, 2, 4, 9 }
};
printf ("Original matrix:\n");
displayMatrix (sampleMatrix);
scalarMultiply (sampleMatrix, 2);
printf ("\nMultiplied by 2:\n");
displayMatrix (sampleMatrix);
scalarMultiply (sampleMatrix, -1);
printf ("\nThen multiplied by -1:\n");
displayMatrix (sampleMatrix);
return 0;
}
// Function to multiply a 3 x 5 array by a scalar
void scalarMultiply (int matrix[3][5], int scalar)
{
int row, column;
for ( row = 0; row < 3; ++row )
for ( column = 0; column < 5; ++column )
matrix[row][column] *= scalar;
}
void displayMatrix (int matrix[3][5])
{
int row, column;
for ( row = 0; row < 3; ++row ) {
for ( column = 0; column < 5; ++column )
printf ("%5i", matrix[row][column]);
printf ("\n");
}
}