C语言实现输入字母判断是星期几

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");
  }
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

回忆式~过去.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值