Thread: Probablity algorithm for N choose M in C or C++

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    1

    Probablity algorithm for N choose M in C or C++

    I am looking for a c++ or c version of a function that will implement N choose M.


    i.e. set A= {a,b,c,d)
    N=4
    M=2

    4 choose 2 from set A I get 6 total combos = N!/M!*(N-M)!

    ab
    ac
    ad
    bc
    bd
    cd


    I tried to develop it using recursion, but I just don't see it.

    Any help or pointers would be very helpful.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by kappajacko View Post
    I tried to develop it using recursion, but I just don't see it.
    Are you trying to compute the probability (given random selection) or are you actually trying to generate the subsets?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM