Write a C program to display the month of year using enumeration.
Input:
6
Output
June
#include <stdio.h>
//January, February, March, and April, May, June, and July, August, September, October, November, December
enum Month {
JANUARY = 1,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBER,
DECEMBER
};
int main() {
// Write C code here
enum Month monthOfYear = 6;
switch(monthOfYear) {
case JANUARY: printf("January");
break;
case FEBRUARY: printf("February");
break;
case MARCH: printf("March");
break;
case APRIL: printf("April");
break;
case MAY: printf("May");
break;
case JUNE: printf("June");
break;
case JULY: printf("July");
break;
case AUGUST: printf("August");
break;
case SEPTEMBER: printf("September");
break;
case OCTOBER: printf("October");
break;
case NOVEMBER: printf("November");
break;
case DECEMBER: printf("December");
break;
}
return 0;
}
Comments
Leave a comment