被100整除的年份必须要被400整除才是闰年,像2100年就不是闰年
有两个类似的程序:
输入年和月,输出该月有多少天?(我们的作业题,嘿嘿) 在TURBO C V2.01 下调试通过。
第一个:
#include "stdio.h"
#include "conio.h"
main ()
{
int year,month;
clrscr ();
printf ("please input number like this: [year],[month]\n\n");
scanf ("[%d],[%d]",&year,&month);
printf("\n");
if (year%4==0&&year%100!=0||year%400==0)
{
printf ("year=%d;month=%d;",year,month);
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:printf ("day=31\n\n"); break;
case 2:printf ("day=29\n\n"); break;
case 4:
case 6:
case 9:
case 11:printf ("day=30\n\n"); break;
default:printf ("the number is error!\n\n"); break;
}
}
else
{
printf ("year=%d;month=%d;",year,month);
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:printf ("day=31\n\n"); break;
case 2:printf ("day=28\n\n"); break;
case 4:
case 6:
case 9:
case 11:printf ("day=30\n\n"); break;
default:printf ("the number is error!\n\n"); break;
}
}
}
第二个:
#include "stdio.h"
#include "conio.h"
main()
{
int year,month;
clrscr();
printf("please input number like this: [year],[month]\n");
printf("\n\n");
scanf("[%d],[%d]", &year, &month);
if(year%4==0&&year%100!=0||year%400==0)
if(1==month||3==month||5==month||7==month||8==month||10==month||12==month)
printf ("day=31\n");
else if (2==month)
printf ("day=29\n");
else printf("day=30\n");
else
if (1==month||3==month||5==month||7==month||8==month||10==month||12==month)
printf("day=31\n");
else if (2==month) printf("day=28\n");
else printf("day=30\n");
}