编程题 限C语言

来源:百度知道 编辑:UC知道 时间:2024/09/23 21:23:10
某幼儿园只招收2至6岁的小孩。2、3岁入小班,4岁入中班,5、6岁入大班。给出一个孩子的年龄,请问他应该被分到什么班。你的程序需要从标准输入设备(通常为键盘)中读入多组测试数据。每组输入数据占一行,其中只包含一个整数i(1≤i≤10),表示一个孩子的年龄。在行首和行尾没有多余的空格。

#include <stdio.h>
int main()
{
int age = 0;
while(1){
printf("请输入年龄:");
scanf("%d",&age);
if(age == 0)
{
break;
}
if(age>=2 && age <=3)
{
printf("此孩子分到小班\n");
}
else if(age == 4)
{
printf("此孩子分到中班\n");
}
else if(age >=5 && age<=6)
{
printf("此孩子分到大班\n");
}
else
{
printf("此孩子的年龄不在幼儿园的范围\n");
}
}
}

#include<stdio.h>
void main()
{int i;
printf("please enter the age:\n");
scanf("%d",&i);
if(i>=2&&i<=6)
{ if(i==2||i==3)
printf("he or she should be in small class.\n");
else if(i==4)
printf("he or she should be in mid class.\n");
else
printf("he or she should be in big class.\n");}
else
printf