C# Sharp exercises: Check whether a given year is a leap year or not
C# Sharp Conditional Statement: Exercise-4 with Solution
Write a C# Sharp program to find whether a given year is a leap year or not.
Pictorial Presentation:
Sample Solution:-
C# Sharp Code:
using System;
public class Exercise4
{
public static void Main()
{
int chk_year;
Console.Write("\n\n");
Console.Write("Check whether a given year is leap year or not:\n");
Console.Write("----------------------------------------------");
Console.Write("\n\n");
Console.Write("Input an year : ");
chk_year= Convert.ToInt32(Console.ReadLine());
if ((chk_year % 400) == 0)
Console.WriteLine("{0} is a leap year.\n", chk_year);
else if ((chk_year % 100) == 0)
Console.WriteLine("{0} is not a leap year.\n", chk_year);
else if ((chk_year % 4) == 0)
Console.WriteLine("{0} is a leap year.\n", chk_year);
else
Console.WriteLine("{0} is not a leap year.\n", chk_year);
}
}
Sample Output:
Check whether a given year is leap year or not: ---------------------------------------------- Input an year : 2017 2017 is not a leap year.
Flowchart :
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C# Sharp program to check whether a given number is positive or negative.
Next: Write a C# Sharp program to read age of a candidate and determine whether it is eligible for casting his/her own vote.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework