C#判断闰年函数及举例
生活随笔
收集整理的這篇文章主要介紹了
C#判断闰年函数及举例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//語法:
public static bool IsLeapYear(int year)
//用法舉例:
using System;public class IsLeapYear
{public static void Main(){for (int year = 1994; year <= 2014; year++){if (DateTime.IsLeapYear(year)){Console.WriteLine("{0} is a leap year.", year);DateTime leapDay = new DateTime(year, 2, 29);DateTime nextYear = leapDay.AddYears(1);Console.WriteLine(" One year from {0} is {1}.", leapDay.ToString("d"),nextYear.ToString("d"));} }}
}
C++:
#include<iostream> using namespace std; int main() {int n=0;for(int i=1000;i<2050;i++)if((i%4==0 && i%100!=0)||i%400==0){cout<<i<<endl;n++;}cout<<n<<endl;return 0; }總結
以上是生活随笔為你收集整理的C#判断闰年函数及举例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#获取本机名及IP地址
- 下一篇: C# dataGridView隔行显示不