c语言循环 数据统计问题I can't type Chinese ,very sorry!example:input something that appears like M38,M means this person's sex,and 38 means his/her age.Sex:M(male) or F(female)Age:P or M or F< 18 (P)unk 18~65 (M)iddle-aged ≥ 65 (F)ossil -

来源:学生作业帮助网 编辑:作业帮 时间:2024/08/11 07:42:12
c语言循环 数据统计问题I can't type Chinese ,very sorry!example:input something that appears like M38,M means this person's sex,and 38 means his/her age.Sex:M(male) or F(female)Age:P or M or F< 18 (P)unk 18~65 (M)iddle-aged ≥ 65 (F)ossil -
xT]kA+$tk7|TDa%`0ٽ:]v6MT|ADDAw#؏&l[Z܇d;w94-~={so>>ŻO%@2@0xd1S  0Y}H"$FMˁ.d 0! xhfc }1 Mch>Ń>; q4܄&sۋ50z%YŃ_>f(e7I7j$ 뢁сB\ G+UR BLiPQdR(@Z1i^1g}S9.Z@lvԄ2b1!K`$&7AOQN)ҡ'rˈT놱m*7n3s2}zD/0 ԇBəpm5;`!2n8ޔqIvC! M& *^z/LOKr+ueS]0(OtTPPPLdsv k'0vrx} Oۏ:Ovfg>J(w}Vunʾff,'\@>%³{ p#'> (CfNDl7Jd62L(edAE*jiR`VKIh΅ԓuN=܈/F&;B/nWP+A+S]dU eoy3-朔c2ٙݡP\_2e&PmXӆ̉ٗED-h

c语言循环 数据统计问题I can't type Chinese ,very sorry!example:input something that appears like M38,M means this person's sex,and 38 means his/her age.Sex:M(male) or F(female)Age:P or M or F< 18 (P)unk 18~65 (M)iddle-aged ≥ 65 (F)ossil -
c语言循环 数据统计问题
I can't type Chinese ,very sorry!
example:input something that appears like M38,M means this person's sex,and 38 means his/her age.
Sex:M(male) or F(female)
Age:P or M or F
< 18 (P)unk
18~65 (M)iddle-aged
≥ 65 (F)ossil
------------------------------------Following is the input of an example.
Sex & age:M38
Sex & age:F41
Sex & age:M72
Sex & age:F65
Sex & age:M10
Sex & age:F12
Sex & age:M14
Sex & age:00
------------------------------------This is the result we get.
Total:7 (numbers of persons)
Female:PMF
Male:PPMF (classify their age according to sex)
------------------------------------
I will give credits for who that has helped me!

c语言循环 数据统计问题I can't type Chinese ,very sorry!example:input something that appears like M38,M means this person's sex,and 38 means his/her age.Sex:M(male) or F(female)Age:P or M or F< 18 (P)unk 18~65 (M)iddle-aged ≥ 65 (F)ossil -
why did you say you coundn't type chinese but used chinese title?

you can do like following:

char get_age_char(int age)
{
if(age < 18) return 'P';
if(age < 65) return 'M';
return 'F';
}
main()
{
#define MAX_INPUT 1000
int total_famale = 0, total_male=0;
int age;
char sex;
char male_age[MAX_INPUT], famale_age[MAX_INPUT];

while(1)
{
printf("Sex & age:");
scanf("%c%d", &sex, &age);
if(sex == 'F')
famale_age[total_famale ++] = get_age_char(age);
else if(sex == 'M')
male_age[total_male ++] = get_age_char(age);
else if(sex == '0' && age == 0)
break;
}
famale_age[total_famale] = male_age[total_male] = 0;

printf("Total: %d\n", total_famale + total_male);
printf("Female: %s\nMale: %s\n", female_age, male_age);
}