This commit is contained in:
Bruno Rybársky 2024-02-12 14:35:40 +01:00
parent d2688932ab
commit d750a8b19c
9 changed files with 102 additions and 8 deletions

@ -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)

@ -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++;

47
array2d.c Normal file

@ -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;
}

1
array2d.h Normal file

@ -0,0 +1 @@
int array2D();

25
hviezdicky.c Normal file

@ -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;
}

11
hviezdicky.h Normal file

@ -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

4
main.c

@ -1,5 +1,5 @@
#include "array.h"
#include "hviezdicky.h"
int main() {
return arraydaco();
return stars();
}

4
myRand.c Normal file

@ -0,0 +1,4 @@
#include "myRand.h"
int myrand(int min, int max){
return rand()%(max-min)+min;
}

1
myRand.h Normal file

@ -0,0 +1 @@
int myrand(int min, int max);