用C语言编写一个小宿舍管理程序

来源:百度知道 编辑:UC知道 时间:2024/06/08 10:21:28
那位大虾帮忙用VC++做一个小程序?要求统计一个班的学生的住宿情况,按照学号从小到大的顺序排列并输出这位学生的姓名,所在宿舍号。并统计个宿舍的学生人数。谢谢了

用c行么?事实上vc++完全兼容c的,设有15个人
#include<stdio.h>
#define A 15/*修改这里更改人数*/
void main()
{char name[][20];
int num[],rom[],id[];
int i,j,t;
for(i=0;i<=A;i++)
{printf("Please type on the student%d's name.",i);
for(j=0;j<=20;j++)
{name[i][j]=getchar();
if(name[i][j]='\n')break;
}
printf("Please type on the student%d's rom number.",i);
scanf("%d\n",&rom[i]);
printf("Please type on the student%d's id number.",i);
scanf("%d\n",&id[i]);
num[i]=i;
}
for(i=A-1;i>=0;i--)
{for(j=0;j<=i;j++)
{if(id[j-1]>id[j]
{t=id[j];
id[j]=id[j-1];
id[j-1]=t;
t=num[j];
num[j]=num[j-1];
num[j-1]=t;
}
}