uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

commit 2425721cf91be54df0c8dd453136d5bfd0341d48
parent 0d8935a6a3865e72f81644d6eb069fc3ff9efb4f
Author: Christos Margiolis <christos@margiolis.net>
Date:   Wed,  8 Jan 2020 22:10:42 +0200

initial commmit

Diffstat:
Aassignment-1.5-arrays-pointers-files/combinations/Makefile | 32++++++++++++++++++++++++++++++++
Aassignment-1.5-arrays-pointers-files/combinations/include/combinations.h | 29+++++++++++++++++++++++++++++
Aassignment-1.5-arrays-pointers-files/combinations/src/combinations.c | 202+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aassignment-1.5-arrays-pointers-files/combinations/src/main.c | 23+++++++++++++++++++++++
4 files changed, 286 insertions(+), 0 deletions(-)

diff --git a/assignment-1.5-arrays-pointers-files/combinations/Makefile b/assignment-1.5-arrays-pointers-files/combinations/Makefile @@ -0,0 +1,31 @@ +EXEC = combs + +SRC_DIR = src +OBJ_DIR = obj + +SRC = $(wildcard $(SRC_DIR)/*.c) +OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) + +MKDIR_P = mkdir -p + +CPPFLAGS += -Iinclude +CFLAGS += -Wall +LDFLAGS += -Llib +LDLIBS += -lm + +.PHONY: all clean + +all: $(EXEC) + +$(EXEC): $(OBJ) + $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + $(MKDIR_P) $(OBJ_DIR) + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +run: + ./$(EXEC) + +clean: + $(RM) $(OBJ) $(EXEC)+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/combinations/include/combinations.h b/assignment-1.5-arrays-pointers-files/combinations/include/combinations.h @@ -0,0 +1,29 @@ +#ifndef COMBINATIONS_H +#define COMBINATIONS_H + +#include <stdbool.h> + +int get_n(const char *); +int combinations_count(int); +int factorial(int); +int sum_calc(); +int sum_comb_calc(); +int even_calc(); +int not_printed(); + +int *fill_array(int); + +float frequency(); + +char *get_filename(); + +bool exists_in_array(int *, int, int); +bool is_subset(); + +void x_pair(int *, int *); +void y_pair(int *, int *); +void combinations(int *); +void print_combs(); +void read_file(); + +#endif diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c b/assignment-1.5-arrays-pointers-files/combinations/src/combinations.c @@ -0,0 +1,201 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include "combinations.h" + +#define COMBSN 6 + + +int get_n(const char *varName) +{ + int num; + + do + { + printf("%s (6 < N <= 49): ", varName); + scanf("%d", &num); + } while (num <= 6 || num > 49); + + return num; +} + + +int *fill_array(int N) +{ + int *arr, num, i = 0; + + arr = (int *)malloc(N * sizeof(int)); + + if (arr == NULL) + { + printf("Not enough memory, error.\n"); + exit(1); + } + else + { + do + { + printf("arr[%d]: ", i); + scanf("%d", &num); + + if (num >= 1 && num <= 49) + { + if (i == 0) + { + *(arr + i) = num; + i++; + } + else + { + if (!exists_in_array(arr, N, num)) + { + *(arr + i) = num; + i++; + } + else + printf("Give a different number.\n"); + } + } + else + printf("Give a number in [1, 49].\n"); + + } while (i < N); + } + + return arr; +} + + +bool exists_in_array(int *arr, int N, int num) +{ + int *arrEnd = arr + N - 1; + + while (arr <= arrEnd && *arr != num) + arr++; + + if (arr <= arrEnd) + return true; + else + return false; +} + + +void x_pair(int *x1, int *x2) +{ + do + { + printf("x1: "); + scanf("%d", x1); + printf("x2: "); + scanf("%d", x2); + } while (*x1 < 0 || *x1 > *x2 || *x2 > 6); // 0 ≤ Χ1 ≤ Χ2 ≤ 6 +} + + +void y_pair(int *y1, int *y2) +{ + do + { + printf("y1: "); + scanf("%d", y1); + printf("y2: "); + scanf("%d", y2); + } while (*y1 < 21 || *y1 > *y2 || *y2 > 279); // 21 ≤ Υ1 ≤ Υ2 ≤ 279 +} + + +void combinations(int *arr) +{ + int i, j, temp; + + for (i = 1; i <= COMBSN; i++) + { + for (j = 0; j < COMBSN-1; j++) + { + temp = *(arr + j); + *(arr + j) = *(arr + j + 1); + *(arr + j + 1) = temp; + } + } +} + + +int find_even() +{ + +} + + +int even_calc() +{ + +} + + +int sum_calc() +{ + +} + + +void print_combs() +{ + +} + + +int combinations_count(int N) +{ + int numCombinations; + + numCombinations = factorial(N) / (factorial(6) * factorial(N - 6)); + + return numCombinations; +} + + +int factorial(int num) +{ + int i, fac; + + for (i = 1, fac = 1; i <= num; i++) + fac *= i; + + return fac; +} + + +int sum_comb_calc() +{ + +} + + +int not_printed() +{ + +} + + +float frequency() +{ + +} + + +char *get_filename() +{ + +} + + +bool is_subset() +{ + +} + + +void read_file() +{ + +}+ \ No newline at end of file diff --git a/assignment-1.5-arrays-pointers-files/combinations/src/main.c b/assignment-1.5-arrays-pointers-files/combinations/src/main.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include <stdlib.h> +#include "combinations.h" + + +int main(int argc, char **argv) +{ + int N, K; + int *arr; + int x1, x2, y1, y2; + + N = get_n("N"); + K = get_n("K"); + arr = fill_array(N); + x_pair(&x1, &x2); + y_pair(&y1, &y2); + combinations(arr); + + + free(arr); + + return 0; +}