C语言设备信息统计函数:统计设备总数、已借出设备数和可借设备数
C语言设备信息统计函数:统计设备总数、已借出设备数和可借设备数
该函数用于统计设备总数、已借出设备数和可借设备数。
void statistics(Device device[], int count)
{
int totalDevices = 0; // 设备总数
int borrowedDevices = 0; // 已借出设备数
int i;
for (i = 0; i < count; i++)
{
totalDevices++;
if (strcmp(device[i].borrower, '无') != 0)
{
borrowedDevices++;
}
}
printf("设备总数: %d\n", totalDevices);
printf("已借出设备数: %d\n", borrowedDevices);
printf("可借设备数: %d\n", totalDevices - borrowedDevices);
}
函数参数
入口参数:
device[]: 设备数组,用于存储设备信息count: 设备数量,表示设备数组的长度
出口参数: 无
函数功能
该函数遍历设备数组,统计设备总数和已借出设备数,并计算可借设备数。
函数使用示例
// 定义设备结构体
struct Device {
char borrower[20];
// ... 其他设备信息
};
// 初始化设备数组
Device devices[5];
// ... 设置设备信息
// 调用统计函数
statistics(devices, 5);
输出结果
该函数会输出以下结果:
- 设备总数:
- 已借出设备数:
- 可借设备数:
AI 优化版
原文地址:https://www.cveoy.top/t/topic/pB7y 著作权归作者所有。请勿转载和采集!