Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define size1 100
- struct BookInformation {
- char surname[size1];
- char bookname[size1];
- unsigned int count;
- unsigned int pages;
- unsigned int price;
- };
- void input(struct BookInformation *ptr, unsigned int n);
- unsigned int search(struct BookInformation *ptr, unsigned int n, unsigned int checker);
- void output(struct BookInformation *ptr, unsigned int s, unsigned int k);
- int main(void) {
- struct BookInformation BookInfo[size1], *ptr;
- unsigned int n;
- unsigned int s;
- unsigned int k;
- s = 0;
- k = 0;
- printf("Введите количество книг \n");
- scanf("%u", &n);
- ptr = BookInfo;
- input(BookInfo, n);
- s = search(BookInfo, n, 1);
- k = search(BookInfo, n, 2);
- output(ptr, s, k);
- system("pause");
- return 0;
- }
- void input(struct BookInformation *ptr, unsigned int n) {
- for (unsigned int i = 0; i<n; i++) {
- printf("Введите автора книги №%u: \n", i + 1);
- scanf("%s", &(ptr + i)->surname);
- printf("Введите название книги №%u: \n", i + 1);
- scanf("%s", &(ptr + i)->bookname);
- printf("Введите количество книг №%u: \n", i + 1);
- scanf("%u", &(ptr + i)->count);
- printf("Введите количество страниц книги №%u: \n", i + 1);
- scanf("%u", &(ptr + i)->pages);
- printf("Введите цену книги №%u: \n", i + 1);
- scanf("%u", &(ptr + i)->price);
- system("cls");
- }
- }
- unsigned int search(struct BookInformation *ptr, unsigned int n, unsigned int checker) {
- switch (checker) {
- case 1:
- unsigned int max_price;
- max_price = ptr->price;
- unsigned int s;
- s = 0;
- for (unsigned int i = 0; i<n; i++) {
- if ((ptr + i)->price>max_price) {
- max_price = (ptr + i)->price;
- s = i;
- }
- }
- return s;
- break;
- case 2:
- unsigned max_count;
- max_count = ptr->count;
- unsigned int k = 0;
- for (unsigned int i = 0; i<n; i++) {
- if ((ptr + i)->count>max_count) {
- max_count = (ptr + i)->count;
- k = i;
- }
- }
- return k;
- break;
- }
- }
- void output(struct BookInformation *ptr, unsigned int s, unsigned int k) {
- system("cls");
- printf("Самой дорогой книгой является %u\n", s + 1);
- printf("Фамилия автора: %s\nНазвание книги: %s\nКоличество книг: %u\nКоличество страниц в книге:%u\nЦена:%u\n", (ptr + s)->surname, (ptr + s)->bookname, (ptr + s)->count, (ptr + s)->pages, (ptr + s)->price);
- printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n");
- printf("Самой массовой книгой является %u\n", k + 1);
- printf("Фамилия автора: %s\nНазвание книги: %s\nКоличество книг: %u\nКоличество страниц в книге:%u\nЦена:%u\n", (ptr + k)->surname, (ptr + k)->bookname, (ptr + k)->count, (ptr + k)->pages, (ptr + k)->price);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement