Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string.h>
- #include <locale.h>
- struct toy {
- char name[50];
- int price;
- int count;
- };
- void inputShop(struct toy* shop, int n)
- {
- for (int i = 0; i < n; i++)
- {
- printf("Input toy №%d: ", (i + 1));
- scanf("%s %d %d", &shop[i].name, &shop[i].price, &shop[i].count);
- }
- }
- void printStructs(struct toy* shop, int n)
- {
- for (int i = 0; i < n; i++)
- {
- printf("Name: %s\t Price: %d\t Count: %d\n", shop[i].name, shop[i].price, shop[i].count);
- }
- }
- void main()
- {
- //struct toy shop[3] = { {"Horse", 58, 15}, {"Princess", 72, 20}, {"Flowers", 24, 50}};
- setlocale(LC_ALL, "Rus");
- struct toy shop[3];
- int n = sizeof(shop) / sizeof(shop[0]);
- struct toy temp;
- inputShop(shop, n);
- printf("\n Shop assortment:\n\n");
- printStructs(shop, n);
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < (n - 1); j++)
- {
- if (shop[j].price > shop[j + 1].price)
- {
- temp = shop[j];
- shop[j] = shop[j + 1];
- shop[j + 1] = temp;
- }
- }
- }
- printf("\n Sorted:\n\n");
- printStructs(shop, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement