Formula #1 (Leap year)
Enter a year: 2016
Year is a leap year
The program for the formula is written
in C# programming language and will accept a number as input year. Based
on the conditions it will check whether the year is a leap year or not.
Let’s find out a simple and easy way
to code these formula.
Practical Implementation:
using System;
namespace patternProblem.Formula
{
class Formula1 //Leap year
{
static void Main(string[] args)
{
Console.Write("Enter a year: ");
int
year = Convert.ToInt32(Console.ReadLine());
if
(((year % 100 != 0) && (year % 4 == 0)) || (year % 400 == 0))
{
Console.WriteLine("Year is a leap year");
}
else
{
Console.WriteLine("Year is not a leap year");
}
Console.ReadKey();
}
}
}
Output:
The input
year here is 2016. So, based on the conditions it will check whether the year
is a leap year or not. The output is shown below:
Enter a year: 2016
Year is a leap year
Press any key to continue . . .
For any
query, comment us below.
Skip to Main
Table – Formula
based program
Keep learning and sharing...
No comments:
Post a Comment