#include
int main()
{
int x, y;
printf("Enter a two-digit number:");
scanf("%1d%1d",&x,&y);
if (x<2){ //讨论10~19的两位数
switch (y){
case 0:printf("you enter the number ten\n");break;
case 1:printf("you enter the number eleven\n");break;
case 2:printf("you enter the number twelve\n");break;
case 3:printf("you enter the number thirteen\n");break;
case 4:printf("you enter the number fourteen\n");break;
case 5:printf("you enter the number fifteen\n");break;
case 6:printf("you enter the number sixteen\n");break;
case 7:printf("you enter the number seventeen\n");break;
case 8:printf("you enter the number eighteen\n");break;
case 9:printf("you enter the number nineteen\n");break;
}
}
else{
switch (x){
case 2:printf("you enter the number twenty");break;
case 3:printf("you enter the number thirty");break;
case 4:printf("you enter the number forty");break;
case 5:printf("you enter the number fifty");break;
case 6:printf("you enter the number sixty");break;
case 7:printf("you enter the number seventy");break;
case 8:printf("you enter the number eighty");break;
case 9:printf("you enter the number ninty");break;
}
switch (y){
case 0:printf("\n");break;
case 1:printf("-first \n");break;
case 2:printf("-second\n");break;
case 3:printf("-third\n");break;
case 4:printf("-four\n");break;
case 5:printf("-five\n");break;
case 6:printf("-six\n");break;
case 7:printf("-seven\n");break;
case 8:printf("-eight\n");break;
case 9:printf("-nine\n");break;
}
}
return 0;
}
**其中scanf("%1d%1d",&x,&y);**为什么我想连续输入两位数就要写成%1d(如我想输入45就直接输入45),但是如果我写成%d就不能连续输入了
(我必须输入4空格5才能输出结果)在线求解!
输两个数就要有两个占位符%d,输的时候中间空格隔开,这里不建议用%ld,%ld对应长整形,而你定义的x和y是int型。你只需要记得输入的时候输两个数,中间以空格隔开,输完回车就行了。
有帮助的话采纳一下哦!