C#代码计算2000到2013年中存在几个闰年 详细代码?

2025-04-14 14:13:53
推荐回答(2个)
回答1:

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
       
        static void Main(string[] args)
        {
            
            for (int year = 2000; year <= 2013; year++)
            {
                if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
                {
                    Console.WriteLine("{0}是闰年", year);
               }
            }
            Console.ReadKey();
        }
    }
}

回答2:

int count=0;
for(int i=2000;i<=2013;i++)
{
//能被4整除则为闰年???
if(i%4==0)
{
count++;
}
}