Formula based program

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.
 
Formula based program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

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


Click imagination hunt to read latest blogs.


Keep learning and sharing...

Comments

Popular posts from this blog

SSC CGL 2016 Tier-1 Marks / Result

DATA TYPES IN C#

Pattern printing program

IS STRING MUTABLE OR IMMUTABLE IN .NET?

Top Mutual Funds