top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find if the Year is Leap Year or Not in C# ?

0 votes
458 views
How to find if the Year is Leap Year or Not in C# ?
posted May 24, 2016 by Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

4 Answers

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

namespace AbundantcodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            // How to Check if the year is leap year or not
            int input = 1996;
            if(input %100 ==0)
            {
                if(input%400==0)
                {
                    Console.WriteLine("Leap Year");
                }
                else
                {
                    Console.WriteLine("Not a Leap Year");
                }
            }
            else
            {
                if(input %4 ==0)
                {
                    Console.WriteLine("Leap Year");
                }
                else
                {
                    Console.WriteLine("Not a Leap Year");
                }
            }
            Console.ReadLine();
        }
    }    
}
answer May 24, 2016 by Shivaranjini
0 votes
using System;
namespace Ashok
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the year");
            int i = int.Parse(Console.ReadLine());
            Console.WriteLine($"year is {((i % 4 == 0) ? "leap" : "not leap")} year.");
            Console.ReadLine();
        }
    }
}
answer May 15, 2019 by Rushabh Verma R.
0 votes
using System;

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the year");
            int i = int.Parse(Console.ReadLine());
            Console.WriteLine($"year is {((i % 4 == 0) ? "leap" : "not leap")} year.");
            Console.ReadLine();

        }
    }
}
answer May 15, 2019 by anonymous
0 votes
using System;

namespace ConsoleApp15
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the year");

            bool ashok = DateTime.IsLeapYear(int.Parse(Console.ReadLine()));
            Console.WriteLine(ashok);
            Console.ReadLine();

        }
    }
}
answer May 15, 2019 by Rushabh Verma R.
Similar Questions
0 votes
public class Semaphore
{
private object _mutex = new object;
private int _currAvail;
public Semaphore(int capacity)
{
_currAvail = capacity;
}
public void Wait()
{
lock(_mutex)
{
if ( currAvail == 0) Monitor.Wait(_mutex);
_currAvail --;
}
}
public void Signal()
{
lock(_mutex)
{
_currAvail ++;
Monitor.Pulse(_mutex);
}
}
}
...