C語言判斷某個年份是否是閏年

下面是使用C語言來判斷某個年份是否是閏年的事例代碼。

// Program to determines if a year is a leap year

#include <stdio.h>

int main(void)
{
    int year, rem_4, rem_100, rem_400;

    printf("Enter the year to be tested: ");
    scanf("%i", &year);

    rem_4 = year % 4;
    rem_100 = year % 100;
    rem_400 = year % 400;

    if((rem_4 == 0 && rem_100 != 0) || rem_400 == 0)
    {
        printf("It's a leap year.\n");
    }
    else
    {
        printf("Nope, it's not a leap year.\n");
    }

    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章