C语言switch语句编个小程序

2024-11-24 14:39:30
推荐回答(5个)
回答1:

#include
void main()
{
int age;
printf("please input the child age:");
scanf("%d",&age);
switch(age)
{
case 2:
case 3: printf("%d,enter the Lower class.\n",age); break;
case 4: printf("%d,enter the Middle class.\n",age); break;
case 5:
case 6: printf("%d,enter the Higher class.\n",age); break;
default : printf(" you chlid shuld goto more Higher class.\n");break;
}
}

回答2:

#include
void main()
{
int age;
printf("请输入孩子的年龄:");
scanf("%d",&age);
switch(age)
{
case 2:
case 3:
printf("age:%d,enter Lower class\n",age);
break;
case 4:
printf("age:%d,enter Middle class\n",age);
break;
case 5:
case 6:
printf("age:%d,enter Higher class\n",age);
break;
default:
printf("您输入的有误!\n");
}
}

回答3:

#include
int main()
{
int age;
printf("输入孩子年龄:\n");
scanf("%d",&age);
switch(age)
{
case 2:
case 3:
printf("%d,enter lower class\n",age);
break;
case 4:
printf("%d,enter middle class\n",age);
break;
default:
printf("%d,enter higher class\n",age);
}
return 0;
}

回答4:

int age;scanf(%d,age);switch(age);case(2)printf(%d,age);printf("enter Lower class");break;
case(3)printf(%d,age);printf("enter Lower class");break;case(4)printf(%d,age);printf("enter Middle class");break;case(5)printf(%d,age);printf("enter Higher class");break;case(6)printf(%d,age);printf("enter Higher class");break;

回答5:

我觉得Switch应该是age ,case2和5后面应该也输出printf 因为要输出年龄 如果没有的话就输出的是3岁和6岁