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)




Monday 15 January 2018

IO 6

QUESTION DESCRIPTION

Write a program by using all relational operators. 

Input and Output Format:

Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output.

TEST CASE 1

INPUT

30 40

OUTPUT

Value of 30>40 is:0 
Value of 30>=40 is:0 
Value of 30<40 is:1 
Value of 30<=40 is:1

EXPLANATION :

The code requires you to accept 2 numbers from the user and check them for ">" , "<" , "<=" , ">=" and print '1' or '0' for "true" or "false" respectively according to the output format.


ALGORITHM :

This is a simple algorithm, as the result of the conditional statements (>,<,>=,<=) is an integer ("0" for "false" and "1" for "true"), we directly print the result of the conditional statements.

Steps :
  • Accept the values of first and the second number
  • Print the results of conditional statements in this order :
    • Greater than
    • Greater than equal to
    • Less than
    • Less than equal to

Remember the spacing in the output and the end of line


SOLUTION :  (Please use this as reference only)