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#判断闰年函数及举例)