酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

#include <stdio.h> #include <stdlib.h> // 定义图书结构体 typedef struct { char title[50]; char author[50]; float price; } book; // 定义图书表 book booktable[100]; int bookcount = 0; // 根据指定图书个数,逐个输入图书信息 void inputbookinfo(int count) { for (int i = 0; i < count; i++) { printf("请输入第%d本图书的标题:", i+1); scanf(" %[^\n]", booktable[bookcount].title); printf("请输入第%d本图书的作者:", i+1); scanf(" %[^\n]", booktable[bookcount].author); printf("请输入第%d本图书的价格:", i+1); scanf("%f", &booktable[bookcount].price); bookcount++; }

} int main() { int count; printf("请输入要录入的图书数量:"); scanf("%d", &count); inputbookinfo(count); printf("\n图书录入完成,录入的图书信息如下:\n"); for (int i = 0; i < bookcount; i++) { printf("图书%d:\n", i+1); printf("%s\n", booktable[i].title); printf("作者:%s\n", booktable[i].author); printf("价格:%.2f\n", booktable[i].price); } return 0; } // 示例输入和输出 // 输入 // 请输入要录入的图书数量:2 // 请输入第1本图书的C Programming // 请输入第1本图书的作者:K&R // 请输入第1本图书的价格:20.5 // 请输入第2本图书的Introduction to Algorithms // 请输入第2本图书的作者:Cormen // 请输入第2本图书的价格:30.0 // 输出 // 图书录入完成,录入的图书信息如下: // 图书1: // C Programming // 作者:K&R // 价格:20.50 // 图书2: // Introduction to Algorithms // 作者:Cormen // 价格:30.00 [2024-07-01 00:38:33 | AI写代码神器 | 559点数解答]

相关提问