Tuesday 16 January 2018

Lucy

QUESTION DESCRIPTION

Lucy is celebrating her 15th birthday. Her father promised her that he will buy her a new computer on her birthday if she solves the question asked by him. He asks Lucy to find whether the year on which she had born is leap year or not. Help her to solve this puzzle so that she celebrates her birthday happily. If her birth year is 2016 and it is a leap year display 2016 is a leap year.? Else display 2016 is not a leap year and check with other leap year conditions 


TEST CASE 1


INPUT
 
1900
 
OUTPUT 
 
 1900 is not a leap year
 
 
TEST CASE 2


INPUT
 
2016
 
OUTPUT 
 
2016 is a leap year 


EXPLANATION :

The code requires you to calculate if the given number (Lucy's birth year) is a leap year or not.
(What is a leap year : Leap_year) 

ALGORITHM :
 
The main part of the algo is to determine whether a year is a leap year or not.
 
Steps :
  • Input the value (Lucy's Birth Year)
  • Check if the year is leap year or not
  • Print appropriate result
Checking Leap Year :

There are 2 basic conditions for checking a leap year :

  • If a number is divisible by 4,100 and 400 its a leap year
  • If a number is not divisible by 100 but it is divisible by 4 then it is a leap year
Check the result of the above two and print the results accordingly

 
SOLUTION : (Please use this as reference only)




No comments:

Post a Comment