programming-examples/c-sharp/Basic/C# Program to Check Whether the Entered Year is a Leap Year or Not.cs

42 lines
915 B
C#
Raw Normal View History

2019-11-18 14:44:36 +01:00
/*
* C# Program to Check Whether the Entered Year is a Leap Year or Not
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class leapyear
{
static void Main(string[] args)
{
leapyear obj = new leapyear();
obj.readdata();
obj.leap();
}
int y;
public void readdata()
{
Console.WriteLine("Enter the Year in Four Digits : ");
y = Convert.ToInt32(Console.ReadLine());
}
public void leap()
{
if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
{
Console.WriteLine("{0} is a Leap Year", y);
}
else
{
Console.WriteLine("{0} is not a Leap Year", y);
}
Console.ReadLine();
}
}
}
/*
Enter the Year in Four Digits : 1004
1004 is a Leap Year