Home » .Net

C# program to find out the leap years from 1900 to 1950

Learn: How to check whether a year a Leap year or not. In this program, we are going to implement a program that will print Leap years from 1900 to 1950.

To understand the program of leap year, first we should understand the concept of leap year.

A year which follow below conditions is known as leap year:

  1. A year, which is divisible by 4 but not divisible by 100, is known as leap year.
  2. A year, which is divisible by 4, 100 and 400, is known as leap year.
  3. A year, which is divisible by 4, 100 but not divisible by 400 is not a leap year.

For example:

  • 1604 is a leap year.
  • 1605 is not a leap year.
  • 1600 is a leap year.
  • 1900 is not a leap year.

Consider the program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    
    class Program
    {
        static void Main(string[] args)
        {
            int i     = 0;

            for (i = 1900; i <= 1950; i++)
            {   
                if( 
                    ((i % 4==0) && (i % 100 !=0)) ||
                    ((i % 4==0) && (i % 100 ==0) && (i%400==0)) 
                  )
                {
                    Console.Write(i + " ");
                }
            }

            Console.WriteLine();
        }
    }
}

Output

1904 1908 1912 1916 1920 1924 1928 1932 1936 1940 1944 1948




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.