From df2701109f0f2a4a8f2f4afa647864b26215bfc1 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 22 Jan 2024 14:41:15 +0100 Subject: [PATCH] smt --- CMakeLists.txt | 4 +++- array.c | 31 +++++++++++++++++++++++++++++ array.h | 6 ++++++ bomba.c | 4 ++-- calc.c | 14 ++++++------- do_while_znak.c | 2 +- for.c | 10 +++++----- kruh.c | 5 +++-- lepsiznak.c | 11 +++++------ main.c | 6 +++--- main_rovnice.c | 17 ++++++++-------- newoldmain.c | 52 +++++++++++++++++++++++-------------------------- oldmain.c | 6 +++--- tyzden.c | 2 +- znak.c | 11 +++++++---- 15 files changed, 110 insertions(+), 71 deletions(-) create mode 100644 array.c create mode 100644 array.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d5405c..9c9f987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,8 @@ add_executable(skola calc.c do_while_znak.c do_while_znak.h for.c - for.h) + for.h + array.c + array.h) target_link_libraries(skola m) diff --git a/array.c b/array.c new file mode 100644 index 0000000..78017bf --- /dev/null +++ b/array.c @@ -0,0 +1,31 @@ +// +// Created by bruno on 1/15/24. +// + +#include "array.h" +#include "stdio.h" + +int arraydaco() { + int pole[10]; + int i; + float priemer = 0; + for (i = 0; i < 10; i++) { + printf("zadaj %d. prvok poľa: ", i); + scanf("%d", &pole[i]); + } + putchar('\n'); + for (i = 0; i < 10; i++) { + printf("%d. prvok poľa je %d.\n", i, pole[i]); + } + int max = pole[0]; + int sucet = pole[0]; + for (i = 1; i < 10; i++){ + sucet += pole[i]; + if(pole[i] > max){ + max = pole[i]; + } + } + priemer = sucet / 10.0; + printf("\nSúčet je %d, maximum je %d a priemer je %f.\n", sucet, max, priemer); + return 0; +} diff --git a/array.h b/array.h new file mode 100644 index 0000000..9251e20 --- /dev/null +++ b/array.h @@ -0,0 +1,6 @@ +// +// Created by bruno on 1/15/24. +// + + +int arraydaco(); diff --git a/bomba.c b/bomba.c index 67d861c..c52a7f4 100644 --- a/bomba.c +++ b/bomba.c @@ -6,13 +6,13 @@ #include "stdio.h" #include "unistd.h" -int dake_cislo(){ +int dake_cislo() { int a; printf("Zadaj číslo:"); scanf("%d", &a); - do{ + do { printf("%d\n", a); usleep(1000000); a--; diff --git a/calc.c b/calc.c index 662efca..02ee0b9 100644 --- a/calc.c +++ b/calc.c @@ -3,14 +3,14 @@ //#define DOWHILE -int calc(){ +int calc() { char pokracovat = 'a'; - #ifndef DOWHILE +#ifndef DOWHILE while (pokracovat == 'a') { - #endif - #ifdef DOWHILE +#endif +#ifdef DOWHILE do { - #endif +#endif double a = 0; double b = 0; @@ -46,9 +46,9 @@ int calc(){ printf("Vysledok %f %c %f je: %f.\nPrajete si pokračovať(a/n)?\n", a, operacia, b, vysledok); scanf("%s", &pokracovat); } - #ifdef DOWHILE +#ifdef DOWHILE while(pokracovat == 'a'); - #endif +#endif return 0; } \ No newline at end of file diff --git a/do_while_znak.c b/do_while_znak.c index 603b42b..4272bee 100644 --- a/do_while_znak.c +++ b/do_while_znak.c @@ -6,7 +6,7 @@ #include "stdio.h" -int do_while_znak(){ +int do_while_znak() { int c; int pocet = 0; const int koniec = 'k'; diff --git a/for.c b/for.c index 0ec97e7..c1be99b 100644 --- a/for.c +++ b/for.c @@ -5,22 +5,22 @@ #include "for.h" #include "stdio.h" -int for_cyklus(){ +int for_cyklus() { int target; printf("Do akého čísla počítať?"); scanf("%d", &target); printf("Zadal si číslo %d.\n", target); printf("Cyklus FOR:\n"); - for(int i = 0; i <= target; i++){ - if(i % 2 == 1) { + for (int i = 0; i <= target; i++) { + if (i % 2 == 1) { printf("%d\n", i); } } printf("\nCyklus WHILE:\n"); int i = 0; - while(i <= target){ - if(i % 2 == 1) { + while (i <= target) { + if (i % 2 == 1) { printf("%d\n", i); } i++; diff --git a/kruh.c b/kruh.c index 811a387..729a3f2 100644 --- a/kruh.c +++ b/kruh.c @@ -1,7 +1,8 @@ #include #include #include "kruh.h" -int circle(){ + +int circle() { float r = 0; float obsah = 0; float obvod = 0; @@ -10,7 +11,7 @@ int circle(){ printf("\nZadaj polomer:"); scanf("%f", &r); - obsah = pi * pow(r,2); + obsah = pi * pow(r, 2); obvod = 2 * pi * r; printf("\nObsah obdlznika je %.2f a obvod je %.2f.", obsah, obvod); diff --git a/lepsiznak.c b/lepsiznak.c index dd2320e..1e46aca 100644 --- a/lepsiznak.c +++ b/lepsiznak.c @@ -5,22 +5,21 @@ #include "lepsiznak.h" #include "stdio.h" -void invertcase(int *c){ - if (*c >= 'a' && *c <= 'z'){ +void invertcase(int *c) { + if (*c >= 'a' && *c <= 'z') { *c -= 0x20; - } - else if (*c >= 'A' && *c <= 'Z'){ + } else if (*c >= 'A' && *c <= 'Z') { *c += 0x20; } } -int lepsiznak(){ +int lepsiznak() { int c; int pocet = 0; const int koniec = 'k'; - while ( (c = getchar()) != koniec){ + while ((c = getchar()) != koniec) { invertcase(&c); putchar(c); pocet++; diff --git a/main.c b/main.c index 857f1be..4a10034 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ -#include "for.h" +#include "array.h" -int main(){ - return for_cyklus(); +int main() { + return arraydaco(); } \ No newline at end of file diff --git a/main_rovnice.c b/main_rovnice.c index 6eb8d61..a62dfed 100644 --- a/main_rovnice.c +++ b/main_rovnice.c @@ -23,7 +23,8 @@ void trojuholniktyp(int a, int b, int c) { printf(" a je rovnoramenný"); } //pravouhly - else if ((pow(a, 2) + pow(a, 2)) == pow(c, 2) || (pow(b, 2) + pow(c, 2)) == pow(a, 2) || (pow(a, 2) + pow(c, 2)) == pow(b, 2)) { + else if ((pow(a, 2) + pow(a, 2)) == pow(c, 2) || (pow(b, 2) + pow(c, 2)) == pow(a, 2) || + (pow(a, 2) + pow(c, 2)) == pow(b, 2)) { printf(" a je pravouhlý"); } //nic z toho @@ -39,11 +40,11 @@ void trojuholnik() { int c = 0; printf("Zadaj číslo:"); - scanf("%d", & a); + scanf("%d", &a); printf("Zadaj číslo:"); - scanf("%d", & b); + scanf("%d", &b); printf("Zadaj číslo:"); - scanf("%d", & c); + scanf("%d", &c); if (trojuholnikalgo(a, b, c) == 1) { trojuholniktyp(a, b, c); } @@ -58,16 +59,16 @@ void rovnicapriamky() { int y = 0; printf("Zadaj A:"); - scanf("%d", & a); + scanf("%d", &a); printf("Zadaj B:"); - scanf("%d", & b); + scanf("%d", &b); printf("Rovnica priamky je y = %d * x + %d\n", a, b); printf("Zadaj súradnicu bodu x:"); - scanf("%d", & x); + scanf("%d", &x); printf("Zadaj súradnicu bodu y:"); - scanf("%d", & y); + scanf("%d", &y); if (((a * x) + b) == y) { printf("Bod [%d; %d] leží na priamke y = %d * x + %d.\n", x, y, a, b); diff --git a/newoldmain.c b/newoldmain.c index 0c024ad..70d0e72 100644 --- a/newoldmain.c +++ b/newoldmain.c @@ -6,23 +6,23 @@ const float pi = 3.14; -float skruhu(float r){ - return pi * pow(r,2); +float skruhu(float r) { + return pi * pow(r, 2); } -float okruhu(float r){ +float okruhu(float r) { return 2 * pi * r; } -float svalec(float r, float h){ +float svalec(float r, float h) { return (okruhu(r) * h) + 2 * skruhu(r); } -float vvalec(float r, float h){ +float vvalec(float r, float h) { return skruhu(r) * h; } -void valec(){ +void valec() { float r = 0; float h = 0; float objem = 0; @@ -40,15 +40,15 @@ void valec(){ printf("\nObjem valca je %.2f a povrch je %.2f.", objem, povrch); } -float strojuholnik(float a, float va){ +float strojuholnik(float a, float va) { return (a * va) / 2; } -float otrojuholnik(float a, float b, float c){ +float otrojuholnik(float a, float b, float c) { return a + b + c; } -void trojuholnikold(){ +void trojuholnikold() { float a = 0; float b = 0; float c = 0; @@ -76,48 +76,44 @@ void trojuholnikold(){ } -void parne(){ +void parne() { int cislo = 0; printf("Zadaj cislo:"); scanf("%d", &cislo); - if(cislo % 2 == 0){ + if (cislo % 2 == 0) { printf("Cislo %d je parne.\n", cislo); - } - else{ + } else { printf("Cislo %d je neparne.\n", cislo); } } -int porovnavanie(int cislo1, int cislo2, int cislo3){ +int porovnavanie(int cislo1, int cislo2, int cislo3) { int min = 0; - if (cislo1 < cislo2){ - if(cislo1 < cislo3){ + if (cislo1 < cislo2) { + if (cislo1 < cislo3) { min = cislo1; - } - else{ + } else { min = cislo3; } - } - else{ - if(cislo2 < cislo3){ + } else { + if (cislo2 < cislo3) { min = cislo2; - } - else{ + } else { min = cislo3; } } return min; } -int porovnavanietest(int *cisla, int pocet){ +int porovnavanietest(int *cisla, int pocet) { int min = cisla[0]; - for(uint16_t i =0; i