1
This commit is contained in:
parent
20bb9845a0
commit
d4adaf65b0
42
cv2/program.c
Normal file
42
cv2/program.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user