A year is taken as input to check whether it is a leap year or not. The conditions for a year to be a leap year are stated below:

**#** The year is divisible by 4 but not divisible by 100.

**#** For the century years, the years should be divisible by 4 as well as 400 to be a leap year.

**#** If the year is not divisible by 4 then it is not a leap year.

**#** For the century years, if it is divisible by 4 and 100 but not by 400 then that year will not be a leap year.

**For example,**

**#** If we consider the year 2000, it is divisible by 4 as well as 400; therefore, this year is a leap year.

**#** If we consider the year 1900, it is divisible by 4 as well as by 100. But, the year is not divisible by 400. Therefore, the year 1900 is not a leap year.

**#** If the year is 2016, it is not a century year, but it is divisible by 4. So, 2016 is a leap year.

**#** If the year is 2015, it is not divisible by 4, so, it is not a leap year.

INPUT: A year

OUTPUT: Whether the year is a leap year or not.

PROCESS:

Step 1: [taking the input]

Read y [the year to check for leap year]

Step 2: [Checking for leap year]

If y Mod 4 = 0 then

If y Mod 100 = 0 then

If y Mod 400 = 0 then

Print "y is a Leap Year"

Else

Print "y is not a Leap Year"

[End of ‘if’]

Else

Print "y is a Leap Year"

[End of ‘if’]

Else

Print "y is not a Leap Year"

[End of ‘if’]

Step 3: Stop.

__TIME COMPLEXITY:__

if(y % 4 == 0) ----------------------------------- **O(1)**

{

//if the year is divisible by 400

//then it is a leap year else not

if( y % 100 == 0) --------------------------- **O(1)**

{

if ( y % 400 == 0) --------------- **O(1)**

printf("%d is a Leap Year", y);

else ------------------------------- **O(1)**

printf("%d is not a Leap Year", y);

}

//if the year is not divisible by 100 but divisible by 4

//then it is a leap year

else ----------------------------------------- **O(1)**

printf("%d is a Leap Year", y );

}

//if the year is not divisible by 4

//then it is not a leap year

else -------------------------------------------- **O(1)**

printf("%d is not a Leap Year", y);

The time complexity of this program is **O(1)**** **as it needs a constant time to execute.

__SPACE COMPLEXITY:__

The space complexity of this program is **O(1)** as it requires same number of memory spaces to execute for any given input.

Related

- Largest Number of two numbers
- largest number between two or three numbers
- Find Largest Number by Menu Driven
- Even and Odd numbers
- Swapping Two Values
- Swapping values without third variable
- Basic Calculator
- Farenheit to Celsius
- ASCII value
- Average Of Numbers
- Average of Even Numbers
- Average Of Odd Numbers
- Sum of n Numbers
- Sum of n Natural Numbers
- Factorial
- Factorial with Recursion
- Multiplication Table
- Exponential without function
- Number Reverse
- String Reverse
- Fibonacci series
- Fibonacci Series with recursion
- Prime Number
- Prime Numbers between 1 and 100
- Prime Numbers in a given range
- Twin Prime
- Twin Prime Range
- Prime factors of a number
- Prime Factors of range of Numbers
- LCM of N numbers
- GCD of N numbers
- Sum of the digits
- Palindrome Number
- Armstrong Number
- Binary to Decimal
- Binary to Octal
- Binary to HexaDecimal
- Decimal to Binary
- Decimal to Octal
- Decimal to Hexadecimal
- Hexadecimal to Binary
- Hexadecimal to Octal
- Hexadecimal to Decimal
- Octal to Binary
- Octal to Hexadecimal
- Octal to Decimal
- Sorting an Array
- Remove Duplicate Elements from an Array
- Left Rotate of an Array
- Right Rotate by 2 of an Array