Weekly Programming Exercise #2
Not graded. Due Monday, 09/28, before class.
1) Design a program let's you know whether the year is a leap year or not using if-else. You don't have to write the whole program. Just the if-else part where the program decides whether the year is a leap year or not.
This is how you calculate leap years:
1) A year divisible by 4 is a leap year.
2) But a year divisible by 100 is not a leap year.
3) But then a year divisible by 400 is a leap year.
Use the modulus operator to find out if a year is divisible by x. (Remember that the modulus operator (x % y) calculates the remainder of x divided by y?)
There are many ways to implement the same logic.
Try two versions of the program: one using nested-if's and another using non-nested if's.
Also, if you have time, try to implement a re-ordering of the logic above.
For example, check that a year is divisible by 400 first, then check 100, then check 4.
Lastly, is there a way to write all of the above conditions in one line of code?