-->
Showing posts with label how to use loop in enum.. Show all posts
Showing posts with label how to use loop in enum.. Show all posts

program to use loop in enum data type

using codeblocks
----------------------------------------------------------------------------------------------
//enum simple program
#include <stdio.h>
#include <stdlib.h>
enum computer{samsung,LG,apple,hp,acer}; // list of values of enum. value location starts from 0.
enum computer find;                    //variable for computer

int main()
{
    find=acer;                          // assigning position of value acer in set
   for(find=samsung;find<=acer;find++)// find variable runs from samsung to acer. The value runs from 0 to 4.

   {
       printf("location of =%d\n",find);// display that
   }
    return 0;
}

//or
/*
//enum simple program
#include <stdio.h>
#include <stdlib.h>

int main()
{
enum computer{samsung,LG,apple,hp,acer}; // list of values of enum
enum computer find;                    //variable for computer

    for(find=samsung;find<=acer;find++)// find variable runs from samsung to acer. The value runs from 0 to 4.

   {
       printf("location =%d\n",find);// display that
   }
    return 0;
}
*/
//note:- we can also put set of value outside and enum variable inside.
// we can set value inside of set. Then,the other values takes values in increasing order.
------------------------------------------------------------------------------
using turboc++
--------------------------------------------------------------------------------------------
//enum simple program
#include <stdio.h>
#include <stdlib.h>
enum computer{samsung,LG,apple,hp,acer}; // list of values of enum. value location starts from 0.
enum computer find;                    //variable for computer

int main()
{
    find=acer;                          // assigning position of value acer in set
   for(find=samsung;find<=acer;find++)// find variable runs from samsung to acer. The value runs from 0 to 4.

   {
       printf("location of =%d\n",find);// display that
   }
    return 0;
}

//or
/*
//enum simple program
#include <stdio.h>
#include <stdlib.h>

int main()
{
enum computer{samsung,LG,apple,hp,acer}; // list of values of enum
enum computer find;                    //variable for computer

    for(find=samsung;find<=acer;find++)// find variable runs from samsung to acer. The value runs from 0 to 4.

   {
       printf("location =%d\n",find);// display that
   }
    return 0;
}
*/
//note:- we can also put set of value outside and enum variable inside.
// we can set value inside of set. Then,the other values takes values in increasing order.