[練習] 判斷閏年

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            Console.WriteLine("請輸入年份");
            x = Convert.ToInt32(Console.ReadLine());
            if (x % 4 != 0)
            {
                Console.WriteLine("不是閏年");
            }
            else
            {
                if (x % 100 == 0 && x % 400 != 0) //被100整除不被400整除
                {
                    Console.WriteLine("不是閏年");
                }
                else  //被4整除或被400整除
                    Console.WriteLine("是閏年");
            }
            Console.ReadKey();

        }
    }
}

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