代码一:
#include
typedef struct student{
int l;
int w;
int h;
int v;
char name[9];
}stu[10];
void func(int n){
int i, ave = 0, robber, victim;
for(i = 0; i < n; i ++){
scanf("%d %d %d %s", &stu[i].l, &stu[i].w, &stu[i].h, &stu[i].name);
stu[i].v = stu[i].l * stu[i].w * stu[i].h;
ave += stu[i].v;
}
ave = ave / n;
for(i = 0; i < n; i ++){
if(ave < stu[i].v){
robber = i;
}
else if(ave > stu[i].v){
victim = i;
}
}
printf("%s took clay from %s.\n", stu[robber].name, stu[victim].name);
scanf("%d",&n);
if(n != -1){
func(n);
}
else{
return;
}
}
int main(){
int n;
scanf("%d", &n);
if(n != -1){
func(n);
}
else
return;
}
代码二:
#include
struct student{
int l;
int w;
int h;
int v;
char name[9];
}stu[10];
void func(int n){
int i, ave = 0, robber, victim;
for(i = 0; i < n; i ++){
scanf("%d %d %d %s", &stu[i].l, &stu[i].w, &stu[i].h, &stu[i].name);
stu[i].v = stu[i].l * stu[i].w * stu[i].h;
ave += stu[i].v;
}
ave = ave / n;
for(i = 0; i < n; i ++){
if(ave < stu[i].v){
robber = i;
}
else if(ave > stu[i].v){
victim = i;
}
}
printf("%s took clay from %s.\n", stu[robber].name, stu[victim].name);
scanf("%d",&n);
if(n != -1){
func(n);
}
else{
return;
}
}
int main(){
int n;
scanf("%d", &n);
if(n != -1){
func(n);
}
else
return;
}
代码一比代码二仅仅是在struct前多写了一个typedef,为什么二就可以正常运行,一就不可以呢?