In: Computer Science
Write a C program that reads an integer value. Assume it is the number of a month of the year; print out the name of that month (Hint: months need to be captured in an array).
Implement theprogram as follows:
Program:
#include <stdio.h>
int main()
{
int month_num; /* declare month_num to store month number */
char months[12][20] = { /* declare 2-dimensional array to store month names */
"January", "February",
"March", "April",
"May", "June",
"July", "August",
"September", "October",
"November", "December"
};
printf("Enter the number of a month : "); /* ask the user to enter a month number */
scanf("%d", &month_num); /* read number from user */
printf("Month : %s", months[month_num-1]); /* Print month name corresponding to month_num */
return 0;
}
Screenshot:
Output:
Please don't forget to give a Thumbs Up.