Given an integer which represents the year, the task is to check if this is a leap year, with the help of Ternary Operator.
A year is a leap year if the following conditions are satisfied:
- Year is multiple of 400.
- Year is multiple of 4 and not multiple of 100.
Following is pseudo code
if year is divisible by 400 then is_leap_year else if year is divisible by 100 then not_leap_year else if year is divisible by 4 then is_leap_year else not_leap_year
Below is the implementation of the above approach:
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.