add cviko 2_2
This commit is contained in:
parent
157f09015f
commit
5afd8f1f3c
6 changed files with 295 additions and 0 deletions
93
Cviko2_2/.gitignore
vendored
Normal file
93
Cviko2_2/.gitignore
vendored
Normal file
|
@ -0,0 +1,93 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/c,visualstudiocode,linux
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=c,visualstudiocode,linux
|
||||
|
||||
### C ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/c,visualstudiocode,linux
|
||||
main
|
13
Cviko2_2/Makefile
Normal file
13
Cviko2_2/Makefile
Normal file
|
@ -0,0 +1,13 @@
|
|||
all: main
|
||||
|
||||
CC = gcc
|
||||
override CFLAGS += -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-result -Wno-unknown-pragmas -pedantic -lm
|
||||
|
||||
main: main.c
|
||||
$(CC) $(CFLAGS) -O1 ./*.c -o "$@"
|
||||
|
||||
main-debug: main.c
|
||||
$(CC) $(CFLAGS) -O1 -g ./*.c -o "$@"
|
||||
|
||||
clean:
|
||||
rm -f main main-*
|
51
Cviko2_2/README.md
Normal file
51
Cviko2_2/README.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
# Replit Template
|
||||
|
||||
**Branch switching**
|
||||
```
|
||||
git switch "branch_name"
|
||||
git submodule update --init
|
||||
```
|
||||
|
||||
**Submodule updates**
|
||||
```
|
||||
git submodule update --init --remote
|
||||
git checkout main -- README.md student-config.sh .tests/.gitignore .tests/config.sh .tests/README.md -p
|
||||
```
|
||||
|
||||
## Creating new branches
|
||||
```
|
||||
BRANCH="branch_name"
|
||||
git branch -c main "$BRANCH"
|
||||
git submodule set-branch --branch "$BRANCH" solution
|
||||
```
|
||||
|
||||
## Propagating changes from master
|
||||
```
|
||||
git fetch
|
||||
for BRANCH in $(git branch -r | grep -E -o "\d{2}-\d{2}-.*");
|
||||
do
|
||||
echo "\nRebase $BRANCH"
|
||||
read
|
||||
git branch -D $BRANCH
|
||||
git checkout $BRANCH || break
|
||||
git reset --hard origin/"$BRANCH" || break
|
||||
git rebase master || break
|
||||
git push --force || break
|
||||
done
|
||||
```
|
||||
|
||||
## Propagating changes of scripts
|
||||
```
|
||||
git fetch
|
||||
for BRANCH in $(git branch -r | grep -E -o "\d{2}-\d{2}-.*");
|
||||
do
|
||||
echo "\nSync test scripts on $BRANCH"
|
||||
read
|
||||
git branch -D $BRANCH
|
||||
git checkout $BRANCH || break
|
||||
git submodule update --remote .tests/scripts || break
|
||||
git add .tests/scripts || break
|
||||
git commit -m "feat: sync latest test scripts" || break
|
||||
git push || break
|
||||
done
|
||||
```
|
103
Cviko2_2/main.c
Normal file
103
Cviko2_2/main.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include "types.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define ARRAY_LENGTH 5
|
||||
#define MERGED_ARRAY_LENGTH 2 * ARRAY_LENGTH
|
||||
|
||||
int* ask_for_numbers(){
|
||||
static int p[ARRAY_LENGTH];
|
||||
for (int i = 0; i < ARRAY_LENGTH; ++i) {
|
||||
printf("Enter number (%d/%d):\n",i+1,ARRAY_LENGTH);
|
||||
scanf("%d",&p[i]);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void read_print_array_reverse() {
|
||||
//TODO 1. Read an array of numbers of length ARRAY_LENGTH from stdin.
|
||||
int* p = ask_for_numbers();
|
||||
|
||||
//TODO 2. Print read array in reversed order to stdout.
|
||||
for (int i = ARRAY_LENGTH - 1; i >= 0; --i) {
|
||||
printf("%d ",p[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void read_print_array_max() {
|
||||
int* p = ask_for_numbers();
|
||||
|
||||
//TODO 2. Find maximum value and print it to stdout.
|
||||
int max = p[0];
|
||||
for (int i = 1; i < ARRAY_LENGTH; ++i) {
|
||||
if(p[i] > max){
|
||||
max = p[i];
|
||||
}
|
||||
}
|
||||
|
||||
printf("The max of the numbers entered is %d",max);
|
||||
return;
|
||||
}
|
||||
|
||||
void read_print_array_avg() {
|
||||
//TODO 1. Read an array of numbers of length ARRAY_LENGTH from stdin.
|
||||
int* p = ask_for_numbers();
|
||||
|
||||
//TODO 2. Calculate average value and print it to stdout.
|
||||
int all = 0;
|
||||
for (int i = 0; i < ARRAY_LENGTH; ++i) {
|
||||
all += p[i];
|
||||
}
|
||||
|
||||
printf("The average value of the array is %.2f",(double)all/ARRAY_LENGTH);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void read_print_array_merge() {
|
||||
//TODO 1. Read 2 arrays of numbers, each of length ARRAY_LENGTH from stdin.
|
||||
printf("ARRAY 1\n");
|
||||
int* p = ask_for_numbers();
|
||||
|
||||
printf("ARRAY 2\n");
|
||||
int* q = ask_for_numbers();
|
||||
|
||||
//TODO 2. To 3rd array of length MERGED_ARRAY_LENGTH copy first and
|
||||
//second arrays respectively and resulting third array print to stdout.
|
||||
int m[MERGED_ARRAY_LENGTH];
|
||||
for (int i = 0; i < MERGED_ARRAY_LENGTH; ++i) {
|
||||
if(i < ARRAY_LENGTH){
|
||||
m[i] = p[i];
|
||||
}
|
||||
else{
|
||||
m[i] = q[i-ARRAY_LENGTH];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MERGED_ARRAY_LENGTH; ++i) {
|
||||
printf("%d ",m[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TEST_BUILD
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("\n--read_print_array_reverse--\n");
|
||||
read_print_array_reverse();
|
||||
|
||||
printf("\n--read_print_array_max--\n");
|
||||
read_print_array_max();
|
||||
|
||||
printf("\n--read_print_array_avg--\n");
|
||||
read_print_array_avg();
|
||||
|
||||
printf("\n--read_print_array_merge--\n");
|
||||
read_print_array_merge();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
11
Cviko2_2/types.h
Normal file
11
Cviko2_2/types.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
// OBSAH TOHOTO SOUBORU NEUPRAVUJTE
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
void read_print_array_reverse();
|
||||
void read_print_array_max();
|
||||
void read_print_array_avg();
|
||||
void read_print_array_merge();
|
||||
|
||||
#endif
|
24
LICENSE
Normal file
24
LICENSE
Normal file
|
@ -0,0 +1,24 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
Loading…
Reference in a new issue