The following code checks whether the year entered by the user is a Leap Year. If the condition specified in the if statement is true, the statements in the if block are executed. And if the condition specified in the if statement is false , the statement in the else block are executed.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int Year; Console.WriteLine("Enter the year: "); Year = Convert.ToInt32(Console.ReadLine()); if ((Year % 4 == 0) && (Year % 100 != 0 || Year % 400 == 0)) { Console.WriteLine("The Year you have entered is a Leap Year {0}.", Year); } else { Console.WriteLine("The Year you have entered is not a Leap Year {0}.", Year); } Console.ReadLine(); } } }
Output:
No comments:
Post a Comment