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 all years in array of years if they are leap years or not in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        int[] array = { 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 1900, 1800, 1700, 1600 };

        foreach (int year in array) {
            if (DateTime.IsLeapYear(year)) {
                Console.WriteLine($"{year} is a leap year");
            } else {
                Console.WriteLine($"{year} is NOT a leap year");
            }
        }
    }
}




/*
run:

2023 is NOT a leap year
2022 is NOT a leap year
2021 is NOT a leap year
2020 is a leap year
2019 is NOT a leap year
2018 is NOT a leap year
2017 is NOT a leap year
2016 is a leap year
1900 is NOT a leap year
1800 is NOT a leap year
1700 is NOT a leap year
1600 is a leap year

*/

 



answered Jul 8, 2023 by avibootz

Related questions

1 answer 99 views
1 answer 92 views
92 views asked Oct 18, 2024 by avibootz
2 answers 160 views
160 views asked Feb 13, 2021 by avibootz
2 answers 208 views
208 views asked Feb 13, 2021 by avibootz
...