C#小練習(判斷某年是否為閏年)
阿新 • • 發佈:2019-01-05
/* (程式頭部註釋開始) * 程式的版權和版本宣告部分 * Copyright (c) 2011, 煙臺大學計算機學院學生 * All rights reserved. * 檔名稱: * 作 者: 臧鵬 * 完成日期: 2012 年 9月 16日 * 版 本 號: 001 * 對任務及求解方法的描述部分 * 輸入描述: * 問題描述:輸入一個年份,判斷是否潤年(被4整除,且不被100整除,或者被400整除) * 程式輸出: * 程式頭部的註釋結束 */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Console.Write("請輸入一個年份:"); string s = Console.ReadLine(); int x = int.Parse(s); if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0) Console.WriteLine("{0}是閏年", x); else Console.WriteLine("{0}不是閏年", x); Console.ReadKey(false); } } }