Sunday, 9 April 2017

C# Program to Check Whether the Entered Year is a Leap Year or Not

  1. /*
  2.  * C# Program to Check Whether the Entered Year is a Leap Year or Not
  3.  */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8.  
  9. namespace Program
  10. {
  11.     class leapyear
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             leapyear obj = new leapyear();
  16.             obj.readdata();
  17.             obj.leap();
  18.         }
  19.         int y;
  20.         public void readdata()
  21.         {
  22.             Console.WriteLine("Enter the Year in Four Digits : ");
  23.             y = Convert.ToInt32(Console.ReadLine());
  24.         }
  25.         public void leap()
  26.         {
  27.             if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
  28.             {
  29.                 Console.WriteLine("{0} is a Leap Year", y);
  30.             }
  31.             else
  32.             {
  33.                 Console.WriteLine("{0} is not a Leap Year", y);
  34.             }
  35.             Console.ReadLine();
  36.         }
  37.     }
  38. }
Here is the output of the C# Program:
Enter the Year in Four Digits : 1004
1004 is a Leap Year

No comments:

Post a Comment