void main() { int year,month,day; printf(“input year month:”); scanf(“%d%d”,&year,&month); switch(month) { case 1: day=31; printf(“day=%d”,day);break; case 2: if(year%400==0||(year%4==0&&year%100!=0)) day=29;
else {day=28;} printf(“day=%d\n”,day); break;
case 3: day=31; printf(“day=%d”,day);break; case 4: day=30; printf(“day=%d”,day);break;
#include”stdio.h” struct { int year; int month; int day; }date; int calc() { int mon[12]={31,29,31,30,31,30,31,31,30,31,30,31}; int all=date.day,i; for(i=0;i<date.month-1;i++) all+=mon[i]; if(date.year%4!=0||date.year%400!=0&&date.year%100==0) all–; return all; } int main() {
void nian(int q,int w) { char y; int s; if(q%4==0&&q%100!=0||q%400==0) y=’y'; else y=’n'; switch(w) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: s=31;break; case 4: case 6 : case 9: case 11: s=30;break; } if(w==2&&y==’y') s=29; else s=28; printf(“%d”,s); } #include<stdio.h> void main() { int year,month; printf(“input the year and month\n”); scanf(“%4d%2d”,&year,&month); nian(year,month); getch(); }
void main()
{
int year,month,day;
printf(“input year month:”);
scanf(“%d%d”,&year,&month);
switch(month)
{
case 1: day=31; printf(“day=%d”,day);break;
case 2:
if(year%400==0||(year%4==0&&year%100!=0))
day=29;
else
{day=28;}
printf(“day=%d\n”,day);
break;
case 3: day=31; printf(“day=%d”,day);break;
case 4: day=30; printf(“day=%d”,day);break;
其他的月份照上面加上去!
│ }
老兄,谢谢啦!!
大家还有别的解法吗?
#include”stdio.h”
struct
{
int year;
int month;
int day;
}date;
int calc()
{
int mon[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int all=date.day,i;
for(i=0;i<date.month-1;i++)
all+=mon[i];
if(date.year%4!=0||date.year%400!=0&&date.year%100==0)
all–;
return all;
}
int main()
{
scanf(“%d%d%d”,&date.year,&date.month,&date.day);
printf(“IT’S %d ” ,calc());
return 0;
}
谢谢你们了!!
hooope
为什么我运行出来的结果与题目要求的结果不一样呢???
你只需要输入例如:200802,就好了
void nian(int q,int w)
{
char y;
int s;
if(q%4==0&&q%100!=0||q%400==0)
y=’y';
else
y=’n';
switch(w)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: s=31;break;
case 4:
case 6 :
case 9:
case 11: s=30;break;
}
if(w==2&&y==’y')
s=29;
else s=28;
printf(“%d”,s);
}
#include<stdio.h>
void main()
{
int year,month;
printf(“input the year and month\n”);
scanf(“%4d%2d”,&year,&month);
nian(year,month);
getch();
}