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/07/05 16:26:37
![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 -](/uploads/image/z/3622483-19-3.jpg?t=c%E8%AF%AD%E8%A8%80%E5%BE%AA%E7%8E%AF+%E6%95%B0%E6%8D%AE%E7%BB%9F%E8%AE%A1%E9%97%AE%E9%A2%98I+can%27t+type+Chinese+%2Cvery+sorry%21example%3Ainput+something+that+appears+like+M38%2CM+means+this+person%27s+sex%2Cand+38+means+his%2Fher+age.Sex%3AM%28male%29+or+F%28female%29Age%3AP+or+M+or+F%3C+18+%28P%29unk+18%7E65+%28M%29iddle-aged+%E2%89%A5+65+%28F%29ossil+-)
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);
}