Program to print the number of days in a given year Last Updated : 15 Feb, 2024 Comments Improve Suggest changes Like Article Like Report Write a program to print the number of days in a given year. Examples: Input: 2023Output: 365Explanation: The year 2023 is not a leap year, therefore the number of days are 365. Input: 2024Output: 366Explanation: 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: C++ #include <iostream> using namespace std; bool isLeapYear(int year) { // Leap year is divisible by 4, but not divisible by 100 // unless divisible by 400 return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } int main() { int year = 2024; // Check if the year is a leap year if (isLeapYear(year)) { cout << "Leap year. It has 366 days." << endl; } else { cout << "Common year. It has 365 days." << endl; } return 0; } Java public class LeapYearChecker { // Function to check if a year is a leap year static boolean isLeapYear(int year) { // Leap year is divisible by 4, but not divisible by 100 unless divisible by 400 return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } public static void main(String[] args) { // Set the year to be checked int year = 2024; // Check if the year is a leap year if (isLeapYear(year)) { System.out.println("Leap year. It has 366 days."); } else { System.out.println("Common year. It has 365 days."); } } } Python3 def is_leap_year(year): # Leap year is divisible by 4, but not divisible by 100 # unless divisible by 400 return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) if __name__ == "__main__": year = 2024 # Check if the year is a leap year if is_leap_year(year): print(f"Leap year. It has 366 days.") else: print(f"Common year. It has 365 days.") C# using System; class LeapYearCheck { // Function to check if a year is a leap year static bool IsLeapYear(int year) { // Leap year is divisible by 4, but not divisible by 100 // unless divisible by 400 return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } static void Main() { int year = 2024; // Check if the year is a leap year if (IsLeapYear(year)) { Console.WriteLine("Leap year. It has 366 days."); } else { Console.WriteLine("Common year. It has 365 days."); } } } JavaScript // Function to check if a year is a leap year function is_leap_year(year) { // Leap year is divisible by 4, but not divisible by 100 unless divisible by 400 return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0); } // Main Program const year = 2024; // Check if the year is a leap year if (is_leap_year(year)) { console.log(`Leap year. It has 366 days.`); } else { console.log(`Common year. It has 365 days.`); } OutputLeap year. It has 366 days. Time Complexity: O(1)Auxiliary space: O(1) Comment More infoAdvertise with us Next Article Program to print the number of days in a given year S sumaiygs7h Follow Improve Article Tags : Android Programming python-dict Practice Tags : python-dict Similar Reads Program to find the number of days in a given month Write a program to find the number of days in a given month. We are given name of a month in lowercase letters, so print the number of days in the month. Note: For February, consider the number of days as 28. Examples: Input: month = "january"Output: 31Explanation: January has 31 days. Input: month 3 min read Program to count the number of days between two years Given two years. Write a program to count the number of days between the two years. Examples: Input: startYear = 1990, endYear = 2001Output: 4383 Explanation: Years 1992, 1996 and 2000 are leap year and all 9 others are non-leap years. So, total number of days are: 366 * 3 + 365 * 9 = 4383 Input: st 4 min read Program to count number of days between two given months Write a program to count the number of days between two given months (including start as well as end month). Assume the number of days in February as 28. Examples: Input: startMonth = "january", endMonth ="january"Output: 31Explanation: January has 31 days. Input: startMonth = "january", endMonth = 6 min read Write a Program to Print 2024 Calendar Write a Program to print the 2024 Calendar. Example: 2024 Calendar: January 2024 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 February 2024 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 M 15+ min read Getting Started with Date and Time Problems in Programming In the world of programming, handling dates and times is essential for many applications. From converting dates to working with time zones, years, weeks, and days, understanding how to code for date and time opens up a world of possibilities. This article will guide you through date and time convers 2 min read Like