Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to check if year is leap year in C#

3 Answers

0 votes
using System;

public class Program
{
	public static void Main(string[] args)
	{
		int year = 2020;

		if (year % 4 == 0) {
			if (year % 100 == 0) {
				if (year % 400 == 0) {
					Console.WriteLine("Leap year");
				}
				else {
					Console.WriteLine("Not a leap year");
				}
			}
			else {
				Console.WriteLine("Leap year");
			}
		}
		else {
			Console.WriteLine("Not a leap year");
		}
	}
}




/*
run:
    
Leap year
    
*/

 



answered Oct 16, 2022 by avibootz
0 votes
using System;

public class Program
{
	public static bool IsLeapYear(int year) {
        if (year % 4 == 0 && year % 100 == 0 && year % 400 == 0)
            return true;
        else if (year % 4 == 0 && year % 100 == 0)
            return false;
        else if (year % 4 == 0)
            return true;
        else
            return false;
    }
    
	public static void Main(string[] args)
	{
		Console.Write(IsLeapYear(2020) ? "Leap Year" : "Not a Leap Year" );
	}
}




/*
run:
    
Leap year
    
*/

 



answered Oct 16, 2022 by avibootz
0 votes
using System;
 
public class Program
{
    public static bool IsLeapYear(int year) {
        return year % 4 == 0 && (year % 100 !=0 || year % 400 == 0);
    }
     
    public static void Main(string[] args)
    {
        Console.Write(IsLeapYear(2020) ? "Leap Year" : "Not a Leap Year" );
    }
}
 
 
 
 
/*
run:
     
Leap year
     
*/

 



answered Oct 16, 2022 by avibootz

Related questions

3 answers 237 views
237 views asked May 23, 2015 by avibootz
2 answers 132 views
132 views asked Oct 16, 2022 by avibootz
3 answers 227 views
3 answers 235 views
1 answer 101 views
3 answers 190 views
...