1. 程式人生 > >c語言判斷一個年份是否是閏年

c語言判斷一個年份是否是閏年

思路是將年份分別除以4,100,400的餘數分別存在four,hundred,fourhundred變數中然後只有兩種情況是閏年其他不是

#include <stdio.h>
void main()
{
int four , hundred , fourhundred , year;
scanf("%d",&year);
four = year % 4;
hundred = year % 100;
fourhundred = year % 400;
if (four == 0 && hundred == 0 && fourhundred == 0)
 printf("this %d is a leap year.", year);
else if (four == 0 && hundred != 0 && fourhundred != 0)
 printf("this %d is a leap year.", year);
else printf("this %d is not a leap %d.",year);
}