47 lines
982 B
C
47 lines
982 B
C
|
#include "stdio.h"
|
||
|
#include "stdlib.h"
|
||
|
#include "time.h"
|
||
|
#include "myRand.h"
|
||
|
|
||
|
#define SIRKA 3
|
||
|
#define VYSKA 3
|
||
|
|
||
|
#if SIRKA > VYSKA
|
||
|
#define MENSIROZMER VYSKA
|
||
|
#else
|
||
|
#define MENSIROZMER SIRKA
|
||
|
#endif
|
||
|
|
||
|
int array2D() {
|
||
|
|
||
|
srand(time(NULL));
|
||
|
|
||
|
int pole[SIRKA][VYSKA];
|
||
|
int i, j;
|
||
|
int diagonalSum = 0;
|
||
|
|
||
|
|
||
|
for (i = 0; i < SIRKA; i++) {
|
||
|
for (j = 0; j < VYSKA; j++) {
|
||
|
// printf("Zadaj prvok pre pole[%d][%d]:", i, j);
|
||
|
// scanf("%d", &pole[i][j]);
|
||
|
pole[i][j] = myrand(0, 9);
|
||
|
}
|
||
|
}
|
||
|
for (i = 0; i < SIRKA; i++) {
|
||
|
for (j = 0; j < VYSKA; j++) {
|
||
|
printf("pole[%d][%d] = %d\n", i, j, pole[i][j]);
|
||
|
}
|
||
|
}
|
||
|
for (i = 0; i < SIRKA; i++) {
|
||
|
for (j = 0; j < VYSKA; j++) {
|
||
|
printf("%d ", pole[i][j]);
|
||
|
}
|
||
|
putchar('\n');
|
||
|
}
|
||
|
for (i = 0; i < MENSIROZMER; i++) {
|
||
|
diagonalSum += pole[i][i];
|
||
|
}
|
||
|
printf("Súčet diagonály je: %d", diagonalSum);
|
||
|
return 0;
|
||
|
}
|