加入双重非法判断的判断是否为闰年(优化版)

程序员成长之旅 · 程序员成长之旅/C语言/自己写的源码 · 85 字

#include<stdio.h>

int main()

{

int year, Num, Error1;

printf("Please enter year(1600~9999):\n");

Error1 = scanf("%d", &year);

if (year >= 1600 & year <= 9999)

{

if (year % 4 == 0)

{

if (year % 100 == 0)

{

if (year % 400 == 0)

{

Num = 1;

}

else

{

Num = 0;

}

}

else

{

Num = 1;

}

}

else

{

Num = 0;

}

if (Num)

{

printf("[%d] is ", year);

}

else

{

printf("[%d] is not ", year);

}

printf("a leap year!");

}

else

{

if (Error1!= 0)

{

printf("You enter nummber [%d] is Error!!", year);

}

else

{

printf("You enter data is Error!!");

}

}

return 0;

}