#include <stdio.h>#include <stdlib.h>#include <time.h>struct Employee { int id; char name[20]; char gender[5]; int age; int performance; char contact[20];};void printEmployee(struct Employee *e) { printf("%d\t %s\t %s\t %d\t %d\t %s\n", e->id, e->name, e->gender, e->age, e->performance, e->contact);}int main() { int n; printf("请输入员工数量:"); scanf("%d", &n); struct Employee emp[n]; for (int i = 0; i < n; i++) { printf("请输入第 %d 位员工的信息:\n", i+1); printf("\t编号:"); scanf("%d", &(emp[i].id)); printf("\t姓名:"); scanf("%s", emp[i].name); printf("\t性别:"); scanf("%s", emp[i].gender); printf("\t年龄:"); scanf("%d", &(emp[i].age)); printf("\t业绩:"); scanf("%d", &(emp[i].performance)); printf("\t联系方式:"); scanf("%s", emp[i].contact); } int groupNum = n / 5; srand(time(NULL)); printf("本次共分为 %d 个小组,各组员工信息如下:\n", groupNum); for (int i = 0; i < groupNum; i++) { printf("第 %d 个小组:\n", i+1); for (int j = 0; j < 5; j++) { int k = rand() % n; printEmployee(&emp[k]); } if (n % 5 != 0 && i == groupNum - 1) { for (int j = 0; j < n % 5; j++) { int k = rand() % n; printEmployee(&emp[k]); } } } return 0;}帮我将这段代码整理一下
时间: 2024-04-01 10:36:49 浏览: 14
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct Employee {
int id;
char name[20];
char gender[5];
int age;
int performance;
char contact[20];
};
void printEmployee(struct Employee *e) {
printf("%d\t %s\t %s\t %d\t %d\t %s\n", e->id, e->name, e->gender, e->age, e->performance, e->contact);
}
int main() {
int n;
printf("请输入员工数量:");
scanf("%d", &n);
struct Employee emp[n];
for (int i = 0; i < n; i++) {
printf("请输入第 %d 位员工的信息:\n", i+1);
printf("\t编号:");
scanf("%d", &(emp[i].id));
printf("\t姓名:");
scanf("%s", emp[i].name);
printf("\t性别:");
scanf("%s", emp[i].gender);
printf("\t年龄:");
scanf("%d", &(emp[i].age));
printf("\t业绩:");
scanf("%d", &(emp[i].performance));
printf("\t联系方式:");
scanf("%s", emp[i].contact);
}
int groupNum = n / 5;
srand(time(NULL));
printf("本次共分为 %d 个小组,各组员工信息如下:\n", groupNum);
for (int i = 0; i < groupNum; i++) {
printf("第 %d 个小组:\n", i+1);
for (int j = 0; j < 5; j++) {
int k = rand() % n;
printEmployee(&emp[k]);
}
if (n % 5 != 0 && i == groupNum - 1) {
for (int j = 0; j < n % 5; j++) {
int k = rand() % n;
printEmployee(&emp[k]);
}
}
}
return 0;
}