From d4adaf65b09c2dea76dfdbfa13511f562ca3c030 Mon Sep 17 00:00:00 2001 From: Deinerovych Date: Wed, 9 Oct 2024 10:04:03 +0200 Subject: [PATCH] 1 --- cv2/program.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 cv2/program.c diff --git a/cv2/program.c b/cv2/program.c new file mode 100644 index 0000000..014c99e --- /dev/null +++ b/cv2/program.c @@ -0,0 +1,42 @@ +#include +#include +#include + +typedef struct { + char name[101]; + double price; +} Pizza; + +int comparePizzas(const void *a, const void *b) { + Pizza *pizzaA = (Pizza *)a; + Pizza *pizzaB = (Pizza *)b; + + if (pizzaA->price < pizzaB->price) { + return -1; + } else if (pizzaA->price > pizzaB->price) { + return 1; + } else { + return strcmp(pizzaA->name, pizzaB->name); + } +} + +int main() { + Pizza menu[] = { + {"Salamovo Fazulova pizza", 7.96}, + {"Sunkova pizza", 5.77}, + {"Bryndzova pizza", 8.67}, + {"Zelerova pizza", 8.86}, + {"Slaninovo Sunkova pizza", 7.55}, + {"Slaninova pizza", 5.16} + }; + int menuSize = sizeof(menu) / sizeof(menu[0]); + + qsort(menu, menuSize, sizeof(Pizza), comparePizzas); + + for (int i = 0; i < menuSize; i++) { + printf("%s\n%.6f\n", menu[i].name, menu[i].price); + } + + return 0; +} +