程序代码:
#include <stdio.h>
#include <stdlib.h>
struct Data {
int year;
int month;
int day;
};
struct library {
char booktitle[50];
char author[10];
struct Data data;
char publishunit[100];
int lendnum;
int stocknum;
};
int main() {
int i, j, n, temp = 0;
struct library book[n];
printf("请输入要处理的图书数量:\n");
fflush(stdout);
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("请输入第%d本书的信息:\n", i + 1);
printf("书名:");
fflush(stdout);
scanf("%s", &book[i].booktitle);
printf("作者:");
scanf("%s", &book[i].author);
printf("出版年月:");
scanf("%s", &book[i].data);
printf("出版社:");
scanf("%s", &book[i].publishunit);
printf("借出数:");
scanf("%s", &book[i].lendnum);
printf("库存数:");
scanf("%s", &book[i].stocknum);
}
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (book[i].publishunit < book[j].publishunit)
{
temp = book[i];
book[i] = book[j];
book[j] = temp;
}
}
printf("\n排序后的图书信息:");
for (i = 0; i < n; i++) {
printf("\n书名: %s\n, 作者: %s\n, 出版年月: %s\n, 出版社: %s\n, 借出数: %s\n, 库存数:%s\n", book[i].booktitle, book[i].author, book[i].data, book[i].publishunit, book[i].lendnum, book [i].stocknum);
}
}
return EXIT_SUCCESS;
}