C语言判断某个年份是否是闰年

来源:互联网 发布:金薇内衣淘宝是真的吗 编辑:程序博客网 时间:2024/06/05 10:20

下面是使用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;}
1 0
原创粉丝点击