c语言果园作物管理系统
时间: 2023-07-03 14:26:49 浏览: 60
好的,下面是一个简单的 C 语言果园作物管理系统的代码示例:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Crop {
char name[20];
int quantity;
};
int main() {
int n;
printf("请输入作物种类数目:");
scanf("%d", &n);
struct Crop *crops = (struct Crop *) malloc(n * sizeof(struct Crop));
if (crops == NULL) {
printf("内存分配失败!\n");
return 1;
}
for (int i = 0; i < n; i++) {
printf("请输入第 %d 种作物名称和数量:", i + 1);
scanf("%s %d", crops[i].name, &crops[i].quantity);
}
for (int i = 0; i < n; i++) {
printf("第 %d 种作物的名称为:%s,数量为:%d\n", i + 1, crops[i].name, crops[i].quantity);
}
free(crops);
return 0;
}
```
这个作物管理系统可以让用户输入作物的种类和数量,然后输出所有作物的名称和数量。这个系统使用了结构体来保存作物的名称和数量,动态分配了内存来存储作物信息,最后释放了内存。当然,这只是一个简单的示例,实际的果园作物管理系统可能需要更多的功能和更复杂的代码。