Thread: what code to enter for subset function?

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    4

    Question what code to enter for subset function?

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

    any example?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    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. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    i don't know how to do in for loop..
    sorry,newbie here

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by ismee View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    i thought using if is the faster way

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by ismee View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    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 subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. terminate 0 - PLEASE HELP
    By Unregistered in forum C Programming
    Replies: 11
    Last Post: 11-21-2001, 07:30 AM