# Thread: what code to enter for subset function?

1. ## what code to enter for subset function?

can anybody tell me what to key to get a subset function?

any example?

2. A "set" can be represented in many different ways in a computer, and depending on your representation, the method to reach a subset would vary.

--
Mats

3. Code:
```i'm using if loop

1,2,3,4,,5 (5 numbers) to search the "5" among them

char list[5]={'a','b','c','d','e'};
if('e'  my question"what to enter between this" list)
printf("e is in the list");```

4. There is no predefined operator or functin to find if something is in an array. You will have to do your own code for that - using a for-loop for example.

--
Mats

5. i don't know how to do in for loop..
sorry,newbie here

6. Originally Posted by ismee
i don't know how to do in for loop..
sorry,newbie here
Then you need to either look at the tutorials on this http://www.cprogramming.com/tutorial, or read another chapter in whatever book you are learning from.

--
Mats

7. i thought using if is the faster way

8. Originally Posted by ismee
i thought using if is the faster way
Whichever way you solve this problem, you will need a form of condition somewhere.

But I'm a bit confused: Faster in what way? Faster than learning about for-loops, or that hardcoding 100 tests instead of looping 100 times is faster - yes, I guess unrolling the loop to 100 linear tests is quicker - but takes up several times more code space, and unless you have gazillions of items to check [either MANY sets, or sets with MANY items in them], I doubt you'd be able to measure the difference.

If you have a SPECIFIC problem that you need to solve, please explain what it is. If you are just discussing minute details without understanding the fundamentals of programming, please go study programming first.

--
Mats

9. How would you aproach such a problem that required no code? Say you have 5 cups and you know that a gremlin is inside of one sleeping. How would you systematically check all five cups to find the gremlin?

Writing down some pseudo code here would be your best place to start as this is a simple enough project. Write down your logical steps in determining if each element of the array contains a letter of your choice.

Start small and build from there.

Popular pages Recent additions