帮帮小白吧
#include<stdio.h>int main(){
int y,m,day_num;
scanf("%d %d",&y,&m);
printf(((y%4==0&&y%100!=0)||y%400==0)?"leap\n":"not leap\n");
if(m>2&&m<6) printf("spring\n");
else if (m>5&&m<9) printf("summer\n");
else if (m>8&&m<11) printf("autumn\n");
else printf("winter\n");
switch(m){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:day_num=31;break;
case 4:
case 6:
case 9:
case 11:day_num=30;break;
case 2:if(y%4==0&&y%100!=0||y%400==0) day_num=29;
else day_num=28;break;
default:printf("error data");
}
printf("days=%d",day_num);
return 0;
}
怎么改动下,输入年份 月份时(当月份不为1-12月),程序运行结果直接就是error data #include<stdio.h>
int main(){
int y,m,day_num;
scanf("%d %d",&y,&m);
if(m<1||m>12)
{
printf("error data");
exit(0);
}
printf(((y%4==0&&y%100!=0)||y%400==0)?"leap\n":"not leap\n");
if(m>2&&m<6) printf("spring\n");
else if (m>5&&m<9) printf("summer\n");
else if (m>8&&m<11) printf("autumn\n");
else printf("winter\n");
switch(m){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:day_num=31;break;
case 4:
case 6:
case 9:
case 11:day_num=30;break;
case 2:if(y%4==0&&y%100!=0||y%400==0) day_num=29;
else day_num=28;break;
default:printf("error data");
}
printf("days=%d",day_num);
return 0;
} 我前些时候帮人写的一个小程序,给你参考
// 编写一个计算天数的程序,用户从键盘中输入年、月、日,在屏幕中输出此日期是该年的第几天。
#include<stdio.h>
void main()
{
int i,year,month,day,days = 0;
int array = {31,29,31,30,31,30,31,31,30,31,30,31};
scanf("%d%d%d",&year,&month,&day);
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
array = 28;
}
for (i = 1;i <= 12;i++) // 计算上个月之前的天数
{
days += array;
if(month == i)
{
days -= array;
break;
}
}
days += day; // 计算今天之前的天数
printf("输入日期是今年的第 %d 天", days);
printf("\n");
}
小甲鱼的铁粉 发表于 2020-10-26 20:13
加的内个exit(0)是啥意思 936241151 发表于 2020-10-26 20:22
加的内个exit(0)是啥意思
就是退出整个运行阶段{:10_312:} 小甲鱼的铁粉 发表于 2020-10-26 20:13
欧克啦 mua 三克油
页:
[1]