php显示某年某月某日,输入某年某月某日,判断这一天是这一年的第几天?
//题目:输入某年某月某日,判断这一天是这一年的第几天?
//1 3 5 7 8 10 12月
//
#include
int singleDay(int year, int month, int day) {
if(year<0) {
printf("error!!!/n");
return -1;
}
if(month>12 || day>31) {
printf("error!!!\n");
return -1;
}
int sday,semonth;
//判断这一年是否为润年
if((year%400==0) || (year%4==0 && year%100!=0)) {
semonth = 29;
printf("%d年为闰年\n\n",year);
}else {
semonth = 28;
printf("%d年为平年\n\n",year);
}
switch(month) {
case 1: sday = day;break;
case 2: sday = 31 + day; break;
case 3: sday = 1*30 + day+1+semonth; break;
case 4: sday = 2*30 + day+2+semonth; break;
case 5: sday = 3*30 + day+2+semonth; break;
case 6: sday = 4*30 + day+3+semonth; break;
case 7: sday = 5*30 + day+3+semonth; break;
case 8: sday = 6*30 + day+4+semonth; break;
case 9: sday = 7*30 + day+5+semonth; break;
case 10: sday = 8*30 + day+5+semonth; break;
case 11: sday = 9*30 + day+6+semonth; break;
case 12: sday = 10*30 + day+6+semonth; break;
default: printf("error!\n");
}
return sday;
}
int main() {
int year,month,day;
int singleday;
printf("请输入几月几日,前面依次为年 月 日,中间以空格分隔,回车结束:");
scanf("%d%d%d",&year,&month,&day);
singleday = singleDay(year,month,day);
printf("所以这一天为这一年的第%d天。\n",singleday);
}
php显示某年某月某日,输入某年某月某日,判断这一天是这一年的第几天?
//题目:输入某年某月某日,判断这一天是这一年的第几天?
//1 3 5 7 8 10 12月
//
#include
int singleDay(int year, int month, int day) {
if(year<0) {
printf("error!!!/n");
return -1;
}
if(month>12 || day>31) {
printf("error!!!\n");
return -1;
}
int sday,semonth;
//判断这一年是否为润年
if((year%400==0) || (year%4==0 && year%100!=0)) {
semonth = 29;
printf("%d年为闰年\n\n",year);
}else {
semonth = 28;
printf("%d年为平年\n\n",year);
}
switch(month) {
case 1: sday = day;break;
case 2: sday = 31 + day; break;
case 3: sday = 1*30 + day+1+semonth; break;
case 4: sday = 2*30 + day+2+semonth; break;
case 5: sday = 3*30 + day+2+semonth; break;
case 6: sday = 4*30 + day+3+semonth; break;
case 7: sday = 5*30 + day+3+semonth; break;
case 8: sday = 6*30 + day+4+semonth; break;
case 9: sday = 7*30 + day+5+semonth; break;
case 10: sday = 8*30 + day+5+semonth; break;
case 11: sday = 9*30 + day+6+semonth; break;
case 12: sday = 10*30 + day+6+semonth; break;
default: printf("error!\n");
}
return sday;
}
int main() {
int year,month,day;
int singleday;
printf("请输入几月几日,前面依次为年 月 日,中间以空格分隔,回车结束:");
scanf("%d%d%d",&year,&month,&day);
singleday = singleDay(year,month,day);
printf("所以这一天为这一年的第%d天。\n",singleday);
}