Create a program that will ask the user to enter five (5) years (in no particular order)
and check whether each year is a leap year or not. Moreover, your program should display:
"More leap years," if there is a greater number of leap years, otherwise display "Fewer leap years."
Thanks for answering this!
using System;
namespace IsLeapYear
{
internal class Program
{
public static void Main(string[] args)
{
/*
Create a program that will ask the user to enter five (5) years (in no particular order)
and check whether each year is a leap year or not. Moreover, your program should display:
"More leap years," if there is a greater number of leap years, otherwise display "Fewer leap years."
*/
Console.WriteLine("Please, enter five (5) years in no particular order: ");
int[] years = new int[5];
byte lyp = 0;
byte isntlyp = 0;
for (int i = 0; i < years.Length; i++)
{
years[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < years.Length; i++)
{
if (DateTime.IsLeapYear(years[i]))
{
Console.WriteLine($"{years[i]} - Leap year!");
lyp++;
}
else
{
Console.WriteLine($"{years[i]} - Is not leap year!");
isntlyp++;
}
}
if(lyp > isntlyp)
Console.WriteLine("More leap years!");
else if(isntlyp > lyp)
Console.WriteLine("Fewer leap years!");
else
Console.WriteLine("Leap years and common years are equal!");
Console.ReadLine();
}
}
}
Comments
Leave a comment