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

This is a discussion on Probablity algorithm for N choose M in C or C++ within the C++ Programming forums, part of the General Programming Boards category; I am looking for a c++ or c version of a function that will implement N choose M. i.e. set ...

  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,012
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,158
    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, 01:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 06: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, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21