C语言实现输入字母判断是星期几 请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。 例如: 程序运行时,提示你"please input first character:" 你输入’f’或者’F’,则程序输出"Friday", 你输入s,则程序进一步提示你"Please input second character:" 此时还需要进一步输入u,程序才输出"Sunday" 如果你输入的字母和任何星期的英文单词首字母都不匹配,则程序需要提示"Illegal input!\n"。
#include "stdio.h"
int main(void)
{
char i,j;
scanf("%c",&i);
if(i>='a'&&i <='z') i=i-32;
if(i>='A'&&i <='Z'){
if(i=='M')
printf("Monday");
else if(i=='W')
printf("Wednesday");
else if(i=='F')
printf("Friday");
else if(i=='S'||i=='T'){
scanf(" %c",&j);
if(i=='S'&&j=='u')
printf("Sunday");
else if(i=='S'&&j=='a')
printf("Saturday");
else if(i=='T'&&j=='u')
printf("Tuesday");
else if(i=='T'&&j=='h')
printf("Thursday");
else
printf("illegal input!\n");
}
else
printf("illegal input!\n");
}
}
#include "stdio.h"
int main() {
// your code
char week1,week2;
scanf("%c",&week1);
if (week1=='M'||week1=='m')
{
printf("Monday");
}
else if (week1=='W'||week1=='w')
{
printf("Wednesday");
}
else if (week1=='F'||week1=='f')
{
printf("Friday");
}
else if (week1=='T'||week1=='t')
{
scanf(" %c",&week2);
if (week2=='U'||week2=='u')
{
printf("Tuesday");
}
else if (week2=='H'||week2=='h')
{
printf("Thursday");
}
}
else if (week1=='S'||week1=='s')
{
scanf(" %c",&week2);
if (week2=='A'||week2=='a')
{
printf("Saturday");
}
else if (week2=='U'||week2=='u')
{
printf("Sunday");
}
}
else
{
printf("illegal input!\n");
}
}
|