-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW55.cpp
48 lines (44 loc) · 916 Bytes
/
HW55.cpp
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
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#pragma warning (disable : 4996)
void randomNumber(int(*)[4],int);
void printResult(int(*)[4], int);
int main()
{
int array[3][4],row;
row = sizeof(array) / sizeof(array[0]);
srand(time(NULL));
randomNumber(array, row);
printResult(array, row);
return 0;
}
void randomNumber(int (*array)[4] , int row)
{
int i, j;
for (i = 0; i<row; i++) {
for (j = 0; j < 4; j++) {
array[i][j] = rand() % 9 + 1;
}
}
}
void printResult(int(*array)[4], int row)
{
int i, j;
int rowtotal, columntotal[4] = {0,};
for (i = 0; i < row ; i++) {
printf("%dÇà\t:",i);
rowtotal = 0;
for (j = 0; j < 4; j++) {
printf("%3d", array[i][j]);
rowtotal += array[i][j];
columntotal[j] += array[i][j];
}
printf("\t%dÇàÀÇ ÇÕ : %d\n",i,rowtotal);
}
printf("¿ÀÇ ÇÕ\t: ");
for (i = 0; i < 4; i++) {
printf("%3d", columntotal[i]);
}
printf("\n");
}