The greatest mistake you can make in life is to be continually fearing you will make one

Wednesday, 24 February 2010

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


 

21 comments:

  1. Can you write a program for structure, union, and typedef

    ReplyDelete
  2. Program1:error(cannot convert int to enum) in today=x;
    So we can clear the error by changing today=(Day)x;

    ReplyDelete
  3. Pretty nice post. I just stumbled upon your blog and wanted to say that I've really enjoyed browsing your blog posts. In any case I will be subscribing to your feed and I hope you write again soon!
    My website info

    ReplyDelete
  4. I was recommended this web site by my cousin.
    I am not sure whether this post is written by him as nobody else know such detailed about my trouble.
    You are amazing! Thanks!

    Feel free to surf to my page: her Comment Is Here

    ReplyDelete
  5. Wow, wonderful blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your website is excellent, as well as the content!


    my page Great Post To read

    ReplyDelete
  6. What's up to all, how is everything, I think every one is getting more from this site, and your views are fastidious in support of new viewers.

    Look at my blog post; I was reading this

    ReplyDelete
  7. Wow, awesome blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your site is magnificent, as well
    as the content!

    Look into my website; for more info
    My page: learn more here

    ReplyDelete
  8. Appreciate the recommendation. Let me try it out.


    Stop by my web blog ... Www.propertywide.co.uk

    ReplyDelete
  9. Why people still make use of to read news papers when in this technological world the whole thing is presented on net?


    Stop by my homepage :: Buy Commercial Property buckinghamshire

    ReplyDelete
  10. Highly descriptive post, I loved that a lot. Will
    there be a part 2?

    Also visit my web-site :: garcinia cambogia review

    ReplyDelete
  11. Excellent blog here! Also your web site loads up very fast!

    What web host are you using? Can I get your affiliate link to your host?

    I wish my site loaded up as quickly as yours lol

    ReplyDelete
  12. We're a bunch of volunteers and opening a brand new scheme in our community. Your site provided us with useful information to work on. You've
    done a formidable process and our whole community will probably be thankful
    to you.

    My web page ... explained here

    ReplyDelete
  13. There is definately a lot to find out about this issue. I
    really like all the points you've made.

    Here is my weblog :: Www.propertywide.co.uk

    ReplyDelete
  14. I do not drop many responses, however i did
    some searching and wound up here "Enum Example programs in C".
    And I actually do have a couple of questions for you if it's allright. Could it be just me or does it seem like a few of these responses look like they are coming from brain dead individuals? :-P And, if you are posting at additional online sites, I'd like to keep up with anything new you have to post.
    Could you make a list of every one of all your community pages like your linkedin profile,
    Facebook page or twitter feed?

    Here is my page: read review

    ReplyDelete
  15. Hi, i think that i saw you visited my site so i came to ?return the favor?
    .I am attempting to find things to improve my site!
    I suppose its ok to use a few of your ideas!!

    Take a look at my blog: a replacement

    ReplyDelete
  16. Everything is very open with a clear description of the issues.
    It was definitely informative. Your website is very useful.
    Thank you for sharing!

    Look at my webpage :: see page

    ReplyDelete
  17. I like the helpful info you provide in your articles. I will bookmark your blog and check again here regularly.
    I am quite sure I will learn lots of new stuff right here!
    Good luck for the next!

    my weblog: porn redtube

    ReplyDelete