(10) 编写一个程序,输入年份和月份,判断该年是否是闰年,并根据给出的月份判断是什么季节和该月。

#include <stdio.h>
int main()
{int x,y;
y>=1&&y<=12;
printf("please imput year and month\n");
scanf("year,month",&x,&y);
if((x%4==0&&x%100!=0)||x%400==0)
printf("this year is full year\n");
else
printf("this year is not full year\n") ;
(10) 编写一个程序,输入年份和月份,判断该年是否是闰年,并根据给出的月份判断是什么季节和该月有多少天?(闰年的条件是年份能被4整除但不能被100整除,或者能被400整除)。我是新手一枚刚刚学c这是我自己弄的程序 总是不对 大神帮我看看吧
#include <stdio.h>
int main()
{int x,y;
y>=1&&y<=12;
printf("please imput year and month\n");
scanf("year,month",&x,&y);
if((x%4==0&&x%100!=0)||x%400==0)
printf("this year is full year\n");
else
printf("this year is not full year\n") ;
{

if(y<=3&&y>=1)
printf(" this month is spring\n");
else if(y<=6&&y>=4)
printf(" this month is summer\n");
else if(y>=7&&y<=9)
printf(" this month is fall\n");
else
printf(" this month is winter\n");
}
{
if(y==1,3,5,7,8,10,12)
printf("this month has 31 days\n");
else if(y==4,6,9,11)
printf("this month has 30 days\n");
else if(y==2&&(x%4==0&&x!=100))
printf("this month has 28 days\n");
else
printf("this month has 29 days");}
return 0;
}

用个判断就行,年份根据是否是闰年的条件判断,月份用个switch语句,列出每个月份的天数,注意二月份有两种可能,所以先判断年份,再判断季节月份。

int main()

{

int year,month;

scanf("%d%d",&year,&month);

if((year%4==0 && year%100!=0) || year%400==0)

printf("闰年");

switch(month)

{

case 1:   printf("春季,31天");  break;

case 2:   if((year%4==0 && year%100!=0) || year%400==0)

printf("春季,29天");

else

printf("春季,28天");    

break;

case 3:                        

case 4:    printf("夏季,30天");           break;

}

return 0;

}

}

扩展资料:

本命令根据提供的逻辑参数的值,来决定是否改变程序的执行位置,如果提供的逻辑参数值为真,程序继续顺序向下执行,否则跳转到下一分支处去继续判断。本命令为初级命令。

参数<1>的名称为“条件”,类型为“逻辑型(bool)”。本条件值的结果决定下一步程序执行位置。

int y,m,day_num;/y代表bai年份,m代表月du份,day_num代表天数

printf("请输入年zhi和月:"); //提示输入年和月

scanf("%d%d",&y,&m); //输入年和月

printf("%d 年",y);

printf(((y%4==0&&y%100!=0)||y%400==0)?"是闰年":"不是闰年");   //判断是否为闰年

printf("\n%d 月是",m);//判断是哪个季节

参考资料来源:百度百科-判断

温馨提示:答案为网友推荐,仅供参考
相似回答