Print the season name of the year based on the month number
Given the month number M, the task is to print the season name of the year based on the month number.
Examples:
Input: M = 5 Output: SPRING Input: M = 1 Output: WINTER
Approach:
- There are 4 main seasons in a year, that is, Summer, Autumn, Winter and Spring.
- The winter months are in December, January and February.
- The spring months in March, April and May.
- The summer months in June, July and August.
- And the autumn months in September, October and November.
- So map the month to the particular season respectively and print it.
Below is the implementation of the above approach:
C++
// C++ program to print the season // name based on the month number #include <bits/stdc++.h> using namespace std; void findSeason(int M) { // Checks out the season according // to the month number entered by the user switch (M) { case 12: case 1: case 2: cout << ("\nWINTER"); break; case 3: case 4: case 5: cout << ("\nSPRING"); break; case 6: case 7: case 8: cout << ("\nSUMMER"); break; case 9: case 10: case 11: cout << ("\nAUTUMN"); break; default: // Handles the condition if number entered // is not among the valid 12 months cout << ("\nInvalid Month number"); break; } } // Driver code int main() { int M = 5; cout << "For Month number: " << M; findSeason(M); M = 10; cout << "\nFor Month number: " << M; findSeason(M); return 0; } // This code is contributed by Rajput-Ji |
chevron_right
filter_none
Java
// Java program to print the season // name based on the month number import java.util.*; public class Seasons { public static void findSeason(int M) { // Checks out the season according // to the month number entered by the user switch (M) { case 12: case 1: case 2: System.out.println("WINTER"); break; case 3: case 4: case 5: System.out.println("SPRING"); break; case 6: case 7: case 8: System.out.println("SUMMER"); break; case 9: case 10: case 11: System.out.println("AUTUMN"); break; default: // Handles the condition if number entered // is not among the valid 12 months System.out.println("Invalid Month number"); break; } } // Driver Code public static void main(String abc[]) { int M = 5; System.out.println("For Month number: " + M); findSeason(M); M = 10; System.out.println("For Month number: " + M); findSeason(M); } } |
chevron_right
filter_none
Python3
# Python3 program to print the season # name based on the month number def findseason (M) : # Taken all the possible # month numbers in the list. list1 = [[12 , 1 , 2], [3 , 4 , 5], [6 , 7 , 8], [9 , 10 , 11]] # Matching the month number # with the above list entries if M in list1[0] : print ( "WINTER" ) elif M in list1[1] : print ( "SPRING" ) elif M in list1[2] : print ( "SUMMER" ) elif M in list1[3] : print ( "AUTUMN" ) else : print ( "Invalid Month Number" ) # Driver Code M = 5print("For Month number:", M); findseason ( M ) M = 10print("For Month number:", M); findseason ( M ) # This code is contributed by Abhishek |
chevron_right
filter_none
C#
// C# program to print the season // name based on the month number using System; class GFG { public static void findSeason(int M) { // Checks out the season according // to the month number entered by the user switch (M) { case 12: case 1: case 2: Console.WriteLine("WINTER"); break; case 3: case 4: case 5: Console.WriteLine("SPRING"); break; case 6: case 7: case 8: Console.WriteLine("SUMMER"); break; case 9: case 10: case 11: Console.WriteLine("AUTUMN"); break; default: // Handles the condition if number entered // is not among the valid 12 months Console.WriteLine("Invalid Month number"); break; } } // Driver Code public static void Main() { int M = 5; Console.WriteLine("For Month number: " + M); findSeason(M); M = 10; Console.WriteLine("For Month number: " + M); findSeason(M); } } // This code is contributed by AnkitRai01 |
chevron_right
filter_none
Output:
For Month number: 5 SPRING For Month number: 10 AUTUMN
Recommended Posts:
- Print a Binary Tree in Vertical Order | Set 2 (Map based Method)
- Program to check if a given year is leap year
- Program to print number pattern
- Program to print multiplication table of a number
- Program to print number with star pattern
- Program to print 'N' alphabet using the number pattern from 1 to n
- Print multiples of Unit Digit of Given Number
- Program to print all the numbers divisible by 3 and 5 for a given number
- Print all the sum pairs which occur maximum number of times
- Program to print the berth of given railway seat number
- Queries to insert, delete one occurrence of a number and print the least and most frequent element
- Program to find century for a year
- Amazon Interview Experience | Set 356 (For 6 Year Experienced)
- Why is programming important for first year or school students?
- Amazon Interview Experience | Set 355 (For 1 Year Experienced)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


