close
輸入西元年 year (1<=year<=9999) 列印此年是否為閏年(leap year)。 輸入西元年為 0 代表結束。 (提示:當西元年被 4 整除而且不被 100 整除,或者是被 400 整除皆為閏年)
輸入:
2012
100
1000
2000
0
輸出:
2012 is a leap year.
100 is not a leap year.
1000 is not a leap year.
2000 is a leap year.
程式碼:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int year;
while(1)
{
scanf("%d",&year);
if(year==0) break;
else
{
if(year%4==0&&year%100!=0||year%400==0)
printf("%d is a leap year.\n",year);
else printf("%d is not a leap year.\n",year);
}
}
}
全站熱搜
留言列表