闰年满足条件
(1)能被4整除,但不能被100整除
或(2)能被400整除
法一:
#include <stdio.h>
#include <stdlib.h>
main()
{
int year,flag;
printf("please enter year:");
scanf("%d",&year);
if((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
flag = 1;
else
flag = 0;
if(flag)
printf("%d is leap year and the days of Feburary are 29. \n",year);
else
printf("%d nonleap year and the days of Feburary are 28\n",year);
}
法二:
#include <stdio.h>
#include <stdlib.h>
main()
{
int year,flag;
printf("please enter year:");
scanf("%d",&year);
flag =((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))? 1 : 0;
if(flag)
printf("%d is leap year and the days of Feburary are 29. \n",year);
else
printf("%d nonleap year and the days of Feburary are 28\n",year);
}