Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday 26 February 2017

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...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...