题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。
程序:
#include <stdio.h>
int main(void)
{char letter;
printf("please input the letter of someday\n");
while ((letter=getchar())!='\n')
{ switch (letter)
{
case 'S':printf("Please input the second letter:\n");
while ((letter=getchar())=='\n')
continue;
if(letter=='a')
printf("saturday\n");
else if (letter=='u')
printf("sunday\n");
else printf("data error\n"); break; case 'F':printf("friday\n");break;
case 'M':printf("monday\n");break;
case 'T':printf("Please input the second letter:\n");
while ((letter=getchar())=='\n') continue; if(letter=='u') printf("tuesday\n"); else if (letter=='h') printf("thursday\n"); else printf("data error\n"); break;
case 'W':printf("wednesday\n");break; default: printf("data error\n");break;
}
}
return 0;}
输出样例: