#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Permutation value


    Hi Team,
    I am trying to write a c program which will result the value of a permutation of a given set.

    Suppose, a set is given {a,b,c,d,e,f}. The result of the progrma will be {abc, abd, abe, abf, ...} like that, means here r=3.

    Can anyone please help me.

    Thanks,
    Sunny
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    I'll give you a starting hint:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAX_SET_SIZE   3
    
    void permute(char *set, size_t size, char *current_set, size_t current_set_size);
    
    int main(void) {
        char set[] = {'a', 'b', 'c', 'd', 'e', 'f'};
        permute(set, sizeof(set)/sizeof(char), NULL, 0);
        return 0;
    }
    
    void permute(char *set, size_t size, char *current_set, size_t current_set_size) {
        char itemset[MAX_SET_SIZE + 1] = {0};
        size_t idx, idx2, i;
        char *remaining_set = NULL;
        
        if (current_set_size == MAX_SET_SIZE) {
            printf("%c%c%c\n", current_set[0], current_set[1], current_set[2]);
            return;
        }
        /* magic code here. I used recursion in my implementation */
    }
    When done, it should print something like this:
    Code:
    abc
    abd
    abe
    abf
    acb
    acd
    ...
    ...
    ...
    fde
    fea
    feb
    fec
    fed
    And there should be 120 rows of output.

    Good luck!
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Its not working sir on Turbo c++ 4.5.
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    Obviously it doesn't work. Did you even read the code and understand what it is doing? You need to actually do some work yourself and fill in some missing parts.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    can you share me your code.actually i am not that much expert in coding.but i need this code.plz share
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    139
    Originally Posted by sk.sunny36
    can you share me your code.actually i am not that much expert in coding.but i need this code.plz share
    As a start point (among many other possibilities):

    - The C Book (a bit old but still a very good book)

    - C in a Nutshell

    - C Programming Language

    Regards,
    Dariyoosh

IMN logo majestic logo threadwatch logo seochat tools logo