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;
}
相关推荐
RuoZoe7 天前
重塑WPF辉煌?基于DirectX 12的现代.NET UI框架Jalium
c语言
祈安_11 天前
C语言内存函数
c语言·后端
norlan_jame12 天前
C-PHY与D-PHY差异
c语言·开发语言
czy878747512 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
m0_5312371712 天前
C语言-数组练习进阶
c语言·开发语言·算法
Z9fish12 天前
sse哈工大C语言编程练习23
c语言·数据结构·算法
代码无bug抓狂人12 天前
C语言之单词方阵——深搜(很好的深搜例题)
c语言·开发语言·算法·深度优先
CodeJourney_J12 天前
从“Hello World“ 开始 C++
c语言·c++·学习
枫叶丹413 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
with-the-flow13 天前
从数学底层的底层原理来讲 random 的函数是怎么实现的
c语言·python·算法