From d750a8b19cccbb8c1beec8105a7f811e03fe958c Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 12 Feb 2024 14:35:40 +0100 Subject: [PATCH] Update --- CMakeLists.txt | 8 +++++++- array.c | 9 ++++----- array2d.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ array2d.h | 1 + hviezdicky.c | 25 +++++++++++++++++++++++++ hviezdicky.h | 11 +++++++++++ main.c | 4 ++-- myRand.c | 4 ++++ myRand.h | 1 + 9 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 array2d.c create mode 100644 array2d.h create mode 100644 hviezdicky.c create mode 100644 hviezdicky.h create mode 100644 myRand.c create mode 100644 myRand.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c9f987..65f35e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,12 @@ add_executable(skola calc.c for.c for.h array.c - array.h) + array.h + array2d.c + array2d.h + myRand.c + hviezdicky.c + hviezdicky.h +) target_link_libraries(skola m) diff --git a/array.c b/array.c index 33552fc..ebf78db 100644 --- a/array.c +++ b/array.c @@ -6,10 +6,7 @@ #include "stdio.h" #include "stdlib.h" #include "time.h" - -int myrand(int min, int max){ - return rand()%(max-min)+min; -} +#include "myRand.h" int arraydaco() { int pole[10]; @@ -53,7 +50,9 @@ int arraydaco() { if (pole[i] < min) { min = pole[i]; } - if (pole[i] % 2){ + } + for (int j = 0; j < 10; ++j) { + if (pole[j] % 2){ neparne++; } else{ parne++; diff --git a/array2d.c b/array2d.c new file mode 100644 index 0000000..a758e5a --- /dev/null +++ b/array2d.c @@ -0,0 +1,47 @@ +#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; +} \ No newline at end of file diff --git a/array2d.h b/array2d.h new file mode 100644 index 0000000..5637ff9 --- /dev/null +++ b/array2d.h @@ -0,0 +1 @@ +int array2D(); \ No newline at end of file diff --git a/hviezdicky.c b/hviezdicky.c new file mode 100644 index 0000000..9b0e611 --- /dev/null +++ b/hviezdicky.c @@ -0,0 +1,25 @@ +// +// Created by bruno on 2/5/24. +// + +#include "hviezdicky.h" +#include "stdio.h" + +int stars() { + int j; //stĺpec + int i; //riadok + int a; //počet riadkov + int b; //počet stĺpcov + printf("Zadaj počet riadkov:"); + scanf("%d", &a); + printf("Zadaj počet stĺpcov:"); + scanf("%d", &b); + putchar('\n'); + for (i = 0; i < a; i++) { + for (j = 0; j < b; j++) { + putchar('*'); + } + putchar('\n'); + } + return 0; +} \ No newline at end of file diff --git a/hviezdicky.h b/hviezdicky.h new file mode 100644 index 0000000..ed43c98 --- /dev/null +++ b/hviezdicky.h @@ -0,0 +1,11 @@ +// +// Created by bruno on 2/5/24. +// + +#ifndef SKOLA_HVIEZDICKY_H +#define SKOLA_HVIEZDICKY_H + +int stars(); + + +#endif //SKOLA_HVIEZDICKY_H diff --git a/main.c b/main.c index 4a10034..ebc6b53 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ -#include "array.h" +#include "hviezdicky.h" int main() { - return arraydaco(); + return stars(); } \ No newline at end of file diff --git a/myRand.c b/myRand.c new file mode 100644 index 0000000..fedd2f0 --- /dev/null +++ b/myRand.c @@ -0,0 +1,4 @@ +#include "myRand.h" +int myrand(int min, int max){ + return rand()%(max-min)+min; +} \ No newline at end of file diff --git a/myRand.h b/myRand.h new file mode 100644 index 0000000..dbd45cd --- /dev/null +++ b/myRand.h @@ -0,0 +1 @@ +int myrand(int min, int max); \ No newline at end of file