Problem C: C语言习题5.11--日期妙算星座

Problem C: C语言习题5.11--日期妙算星座

Time Limit: 1 Sec  Memory Limit: 128 MB

 

Description

近几年星座运势十分流行,据说一年之中根据月份可以分出十二个星座,它们分别是:摩羯座(12.22-1.19),水瓶座(1.20-2.18),双鱼座(2.19-3.20),白羊座(3.21-4.19),金牛座(4.20-5.20),双子座(5.21-6.21),巨蟹座(6.22-7.22),狮子座(7.23-8.22),处女座(8.23-9.22),天秤座(9.23-10.23),天蝎座(10.24-11.22),射手座(11.23-12.21),猴哥对星座很感兴趣,他想快速根据自己的出生日期求出他所属的星座,请你编程帮助他吧~

#include
void constellation(int year,int month,int day); /*函数声明*/
int main()
{
    int year,month,day;
    scanf("%d %d %d",&year,&month,&day);    /*输入变量*/
    constellation(year,month,day);  /*调用函数*/
    return 0;
}

主程序已给出,提交时只需提交constellation函数

Input

日期

Output

星座名称

Sample Input

2000 12 31

Sample Output

摩羯座

HINT

快来算一算你是哪个星座吧~

 

参考答案:

#include 
void constellation(int year,int month,int day); /*函数声明*/
int main()
{
    int year,month,day;
    scanf("%d %d %d",&year,&month,&day);    /*输入变量*/
    constellation(year,month,day);  /*调用函数*/
    return 0;
}
void constellation(int year,int month,int day)/*函数声明*/
{
	if((month==12&&day<=31&&day>=21)||(month==1&&day>=1&&day<=19))
		printf("摩羯座");
	else if((month==1&&day>=20&&day<=31)||(month==2&&day>=1&&day<=18))
		printf("水瓶座");
	else if((month==2&&day>=19&&day<=30)||(month==3&&day>=1&&day<=20))
		printf("双鱼座");
	else if((month==3&&day>=21&&day<=31)||(month==4&&day>=1&&day<=19))
		printf("白羊座");
	else if((month==4&&day>=20&&day<=30)||(month==5&&day>=1&&day<=20))
		printf("金牛座");
	else if((month==5&&day>=21&&day<=31)||(month=6&&day>=1&&day<=21))
		printf("双子座");
	else if((month==6&&day>=22&&day<=30)||(month==7&&day>=1&&day<=22))
		printf("巨蟹座");
	else if((month=7&&day>=23&&day<=31)||(month==8&&day>=1&&day<=22))
		printf("狮子座");
	else if((month==8&&day>=23&&day<=31)||(month==9&&day>=1&&day<=22))
		printf("处女座");
	else if((month==9&&day>=23&&day<=30)||(month==10&&day>=1&&day<=23))
		printf("天秤座");
	else if((month==10&&day>=24&&day<=31)||(month==11&&day>=1&&day<=22))
		printf("天蝎座");
	else if((month==11&&day>=23&&day<=30)||(month==12&&day>=1&&day<=21))
		printf("射手座");
}

编程软件及学习视频下载:点击打开链接

你可能感兴趣的:(c语言基础)