C 练习实例31

**题目:**请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。

**程序分析:**用情况语句比较好,如果第一个字母一样,则判断用情况语句或if语句判断第二个字母。

代码:

cpp 复制代码
/*monday tuesday wednesday thursday friday saturday sunday
  星期一 星期二   星期三    星期四   星期五  星期六   星期日
*/
#include <stdio.h>
int main()
{
	char c;
	printf("Please input a letter:");
	scanf("%c",&c);
	scanf("%c");
	switch(c){
		case 'm':
			printf("monday\n");
			break;
		case 't':
			printf("Please input anothor letter:");
			scanf("%c",&c);
			if(c=='u')
				printf("tuesday\n");
			else if(c=='h')
				printf("thursday\n");
			else
				printf("error!\n");
			break;
		case 'w':
			printf("wednesday\n");
			break;
		case 'f':
			printf("friday\n");
			break;
		case 's':
			printf("Please input anothor letter:");
			scanf("%c",&c);
			if(c=='a')
				printf("saturday\n");
			else if(c=='u')
				printf("sunday\n");
			else
				printf("error!\n");
			break;
		default:
			printf("error!\n");
	}
	return 0;
}
相关推荐
Escalating_xu11 小时前
【C 语言】深入理解指针(4):回调函数、qsort、void * 与泛型排序的模拟实现
java·c语言·开发语言
吠品12 小时前
GitHub 周榜拆解:决策小模型扎堆上位
c语言·开发语言·算法
小师兄吃牛肉13 小时前
C语言篇:内联函数
c语言·开发语言
白山编程大哥13 小时前
C语言篇:语法进阶
c语言·数据结构·算法
Logic10114 小时前
C语言/数据结构动态规划题解:爬楼梯(含坏台阶)——避开障碍物的路径计数
c语言·数据结构·动态规划·时间复杂度·空间复杂度·算法题·爬楼梯
山下梅子酒22514 小时前
洛谷-入门-B2081
c语言
wuminyu15 小时前
Virtual Thread重投递至ForkJoinPool任务队列过程解析
java·linux·c语言·jvm·c++
Navigator_Z15 小时前
LeetCode //C - 1281. Subtract the Product and Sum of Digits of an Integer
c语言·算法·leetcode
iCxhust15 小时前
51单片机电力载波应用开发(七)广播通讯
c语言·开发语言·单片机·嵌入式硬件·51单片机
Hi2024021716 小时前
同一个 NMS 算子,两种语言实现:CUDA C 与 Rust 生成 LLVM IR 和 Vortex 汇编的差异
c语言·汇编·rust·gpgpu·vortex·cudac