#include <stdio.h>
#include <stdlib.h>
struct student {
char name[20];
double height;
double weight;
double bmi;
};
int func(void)
{
char s[100],buf[100];
int c=0,i,j;
FILE *fp;
struct student *data,t;
double h;
/* printf("file name = ");*/
if(!fp) {
return 1;
}
while(fgets(buf
,100,fp
))c
++;
data
=malloc(c
*sizeof(struct student
)); for(i
=0; fgets(buf
,100,fp
); i
++) { sscanf(buf
,"%s %lf %lf",data
[i
].
name,&data
[i
].
height,&data
[i
].
weight); h=data[i].height/100;
data[i].bmi=data[i].weight/h/h;
}
for(i=0; i<c; i++) {
for(j=i+1; j<c; j++) {
if(data[i].bmi<data[j].bmi) {
t=data[i];
data[i]=data[j];
data[j]=t;
}
}
}
for(i=0; i<c; i++) {
printf("%s BMI=%f",data
[i
].
name,data
[i
].
bmi); if(data
[i
].
bmi>25)printf(" himan"); }
return 0;
}
int main(void)
{
func();
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnN0cnVjdCBzdHVkZW50IHsKICBjaGFyIG5hbWVbMjBdOwogIGRvdWJsZSBoZWlnaHQ7CiAgZG91YmxlIHdlaWdodDsKICBkb3VibGUgYm1pOwp9OwoKaW50IGZ1bmModm9pZCkKewogIGNoYXIgc1sxMDBdLGJ1ZlsxMDBdOwogIGludCBjPTAsaSxqOwogIEZJTEUgKmZwOwogIHN0cnVjdCBzdHVkZW50ICpkYXRhLHQ7CiAgZG91YmxlIGg7CgovKiAgcHJpbnRmKCJmaWxlIG5hbWUgPSAiKTsqLwogIHNjYW5mKCIlcyIscyk7CiAgZnA9Zm9wZW4ocywiciIpOwogIGlmKCFmcCkgewogICAgcHJpbnRmKCJmaWxlIG9wZW4gZXJyb3IhXG4iKTsKICAgIHJldHVybiAxOwogIH0KCiAgd2hpbGUoZmdldHMoYnVmLDEwMCxmcCkpYysrOwogIHJld2luZChmcCk7CgogIGRhdGE9bWFsbG9jKGMqc2l6ZW9mKHN0cnVjdCBzdHVkZW50KSk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