Get new post automatically.

Enter your email address:


Enum Example programs in C

Program 1:
Program to find whether week day or week end using enum
#include<stdio.h>
int main()
{
    enum Day {Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};
    enum Day today;
    int x;
    printf("please enter the day of the week(0 to 6)\n");
    scanf("%d",&x);
    today=x;

    if(today==Sunday || today==Saturday)
        printf("Enjoy! Its the weekend\n");
    else
        printf("Week day.do your work\n");
    return 0;
}

Output
Please enter the day of the week(0 to 6)
0
Enjoy! Its the Weekend


Program 2:
Program to find the month 
#include<stdio.h>
int main()
{
    enum months {Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};
    enum months month;
    printf("month=%d\n",month=Feb);//Assign integer value
    return 0;
}
Output
month=2

Program 3:
Program to return the number of days in a month using enum
#include<stdio.h>
int main()
{
    enum months {Jan=31,Feb=28,Mar=31,Apr=30,May=31,Jun=30,Jul=31,Aug=31,Sep=30,Oct=31,Nov=30,Dec=31};
    enum months month;
    printf("days=%d\n",month=Feb);
    return 0;
}
Output
days=28