VOOZH about

URL: https://www.geeksforgeeks.org/android/program-to-print-the-number-of-days-in-a-given-year/

⇱ Program to print the number of days in a given year - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print the number of days in a given year

Last Updated : 15 Feb, 2024

Write a program to print the number of days in a given year.

Examples:

Input: 2023
Output: 365
Explanation: The year 2023 is not a leap year, therefore the number of days are 365.

Input: 2024
Output: 366
Explanation: The year 2024 is a leap year, therefore the number of days are 366.

Approach: To solve the problem, follow the below idea:

To determine the number of days in a given year, you need to consider whether the year is a leap year or not. A year is a leap year if the following conditions are satisfied: 

  • The year is multiple of 400.
  • The year is a multiple of 4 and not a multiple of 100.

So, if it is a leap year the year contains 366 days and if not a leap year, then no. of days in a year are 365.

Below is the implementation of the above approach:


Output
Leap year. It has 366 days.

Time Complexity: O(1)
Auxiliary space: O(1)

Comment
Article Tags:

Explore