美文网首页C#题库
0014-判断闰年

0014-判断闰年

作者: 指尖极光 | 来源:发表于2017-03-13 13:19 被阅读12次

    问题描述

    判断某年是否是闰年。公历纪年法中,能被 4 整除的大多是闰年,但能被 100 整除而不能被 400 整除的年份不是闰年,如 1900 年是平年,2000 年是闰年。

    输入

    一行,仅含一个整数 a(0 < a < 3000)。

    输出

    一行,如果公元 a 年是闰年输出 Y,否则输出 N。

    输入样列

    2006
    

    输出样例

    N
    

    算法实现

    using System;
    
    namespace Questions{
        class Program{
            public static void Main(string[] args){
                int a = int.Parse(Console.ReadLine());
                if (a < 3000 && a > 0 && ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0)) 
                    Console.WriteLine("Y");
                else
                    Console.WriteLine("N");
                Console.ReadKey();
            }
        }
    }

    相关文章

      网友评论

        本文标题:0014-判断闰年

        本文链接:https://www.haomeiwen.com/subject/nfbfnttx.html