From dddbcae40d9a71999a1b4a904322c26646f4bee5 Mon Sep 17 00:00:00 2001 From: Daniel Ryzhuk Date: Wed, 2 Dec 2020 09:07:21 +0000 Subject: [PATCH] Upload files to 'a3' --- a3/program.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 a3/program.c diff --git a/a3/program.c b/a3/program.c new file mode 100644 index 0000000..33fe447 --- /dev/null +++ b/a3/program.c @@ -0,0 +1,57 @@ +#include + +int check(int i, int size, int array[]) +{ + if (i >= size) + { + return 0; + } + else if (array[i] < array[(i - 1) / 2]) + { + return 1; + } + else + { + return check(i * 2 + 1, size, array) + check(i * 2 + 2, size, array); + } +} + +int spaces = 0; +void print(int i, int size, int array[]) +{ + if(i >= size) + { + return; + } + for(int j = 0; j < spaces; j++) + { + printf(" "); + } + printf("%d\n", array[i]); + spaces = spaces + 1; + print(i * 2 + 1, size, array); + print(i * 2 + 2, size, array); + spaces = spaces - 1; +} + +int main() +{ + int array[1000]; + int size = 0; + while(scanf("%d", &array[size]) != EOF) + { + size++; + } + int result = check(0, size, array); + if (result == 0) + { + spaces = 0; + printf("Je to taka kopa:\n"); + print(0, size, array); + } + else + { + printf("Nie je kopa.\n"); + return 0; + } +} \ No newline at end of file