职工管理系统中,如何实现统计不同部门的人数。给出c语言代码
```c
#include<stdio.h>
#include<string.h> //提供strcmp()函数的原型声明
//定义结构体保存职工信息
struct worker {
char name[20]; //姓名
char dept[20]; //部门
};
//定义职工总人数为5,可以根据需要进行修改
int count=5;
void main() {
struct worker staff[5]={{"张三","生产部"},{"李四","市场部"},{"王五","生产部"},{"赵六","财务部"},{"孙七","研发部"}};
int i,product_count=0,market_count=0,finance_count=0,research_count=0;
for(i=0;i<count;i++) { if(strcmp(staff[i].dept,"生产部")==0) product_count++; else if(strcmp(staff[i].dept,"市场部")==0) market_count++; else if(strcmp(staff[i].dept,"财务部")==0) finance_count++; else research_count++; } printf("
生产 部:%d
市场 部:%d
财务 部:%d
研发 部:%d
",product_count,market_count,finance_count,research_
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。