Here's a C program that takes a date as input and outputs the season:
#include <stdio.h>
#include <string.h>
int main() {
char month[10];
int day;
printf("Enter the month: ");
scanf("%s", month);
printf("Enter the day: ");
scanf("%d", &day);
if ((strcmp(month, "January") == 0 && day >= 1 && day <= 31) ||
(strcmp(month, "February") == 0 && day >= 1 && day <= 28) ||
(strcmp(month, "March") == 0 && day >= 1 && day <= 20) ||
(strcmp(month, "December") == 0 && day >= 21 && day <= 31)) {
printf("Winter\\");
}
else if ((strcmp(month, "March") == 0 && day >= 21 && day <= 31) ||
(strcmp(month, "April") == 0 && day >= 1 && day <= 30) ||
(strcmp(month, "May") == 0 && day >= 1 && day <= 31) ||
(strcmp(month, "June") == 0 && day >= 1 && day <= 20)) {
printf("Spring\\");
}
else if ((strcmp(month, "June") == 0 && day >= 21 && day <= 30) ||
(strcmp(month, "July") == 0 && day >= 1 && day <= 31) ||
(strcmp(month, "August") == 0 && day >= 1 && day <= 31) ||
(strcmp(month, "September") == 0 && day >= 1 && day <= 20)) {
printf("Summer\\");
}
else if ((strcmp(month, "September") == 0 && day >= 21 && day <= 30) ||
(strcmp(month, "October") == 0 && day >= 1 && day <= 31) ||
(strcmp(month, "November") == 0 && day >= 1 && day <= 30) ||
(strcmp(month, "December") == 0 && day >= 1 && day <= 20)) {
printf("Fall\\");
}
else {
printf("Invalid date\\");
}
return 0;
}
The program first prompts the user to enter the month and day of the date. It then checks if the input is a valid date by checking if the month and day are within valid ranges for each season. If the input is valid, the program outputs the corresponding season. If the input is not valid, the program outputs an error message.
Note that the program assumes that February always has 28 days and does not handle leap years. If you need to handle leap years, you can modify the program to check if the year is a leap year and adjust the number of days in February accordingly.