Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,187 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,341 people online right now. Registration is fast and FREE... Join Now!




Permutations

 
Reply to this topicStart new topic

Permutations, word permutations (string)

eug5ne
25 Oct, 2007 - 04:58 AM
Post #1

New D.I.C Head
*

Joined: 25 Oct, 2007
Posts: 4



Thanked: 1 times
My Contributions

Here is my code guys. I don't know how to fix the repetitions. Pls help.
CODE
#include <stdio.h>
#include <string.h>

/*Calculate Factorial*/
long factorial( int limit )
{
     if ( limit == 0 )
        return 1;
     else
         return(limit * factorial ( limit - 1 ));
}
/*Print Permutations*/
void permutations (char string[], int limit)
{
     int idx, looper,const_idx;
     char temp;
     char copy[256];
     strcpy(copy, string);
     for(const_idx=0, idx = 1, looper = 0; looper < limit; looper++, idx++)
     {
         if(idx == strlen(string))
         idx = 1;
         /*Shuffle String*/
         temp = string[const_idx];
         string[const_idx] = string[idx];
         string[idx] = temp;

         printf("\n%s",string);
     }
}
int main()
{
    int limit, NofLetters;
    char string[15];
    printf("Enter string here: ");
    gets(string);
    NofLetters = strlen(string);
    limit = factorial(NofLetters);
    
    permutations( string , limit );/*pass string and limit */
    
    getch();
    return 0;
}


User is offlineProfile CardPM
+Quote Post


jjhaag
RE: Permutations
25 Oct, 2007 - 11:17 AM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 7 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
You need to be a little more specific with the problems that you're having. e.g. what the code is supposed to do, what it actually does...

And you don't need to start an entirely new thread, seeing as how this is the same code you were using before (modified, to be sure).

-jjh
User is offlineProfile CardPM
+Quote Post

eug5ne
RE: Permutations
27 Oct, 2007 - 01:20 AM
Post #3

New D.I.C Head
*

Joined: 25 Oct, 2007
Posts: 4



Thanked: 1 times
My Contributions
QUOTE(jjhaag @ 25 Oct, 2007 - 12:17 PM) *

You need to be a little more specific with the problems that you're having. e.g. what the code is supposed to do, what it actually does...

And you don't need to start an entirely new thread, seeing as how this is the same code you were using before (modified, to be sure).

-jjh

Obviously its a permutation program.

hey.. I'm new here. I just've registered. I don't know what ur talking about.
You know, I've been searching in the forums. but all is in C++. This is my code. I didn't copied it, I made it.

Someone help?

This post has been edited by eug5ne: 27 Oct, 2007 - 01:22 AM
User is offlineProfile CardPM
+Quote Post

MorphiusFaydal
RE: Permutations
27 Oct, 2007 - 01:23 AM
Post #4

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,349



Thanked: 31 times
Expert In: Hardware, Networking

My Contributions
Actually, that's C, not C++.

And we will need to know what the code is supposed to do, and what it is doing before we can be of any help.
User is offlineProfile CardPM
+Quote Post

eug5ne
RE: Permutations
28 Oct, 2007 - 03:55 PM
Post #5

New D.I.C Head
*

Joined: 25 Oct, 2007
Posts: 4



Thanked: 1 times
My Contributions
QUOTE(MorphiusFaydal @ 27 Oct, 2007 - 02:23 AM) *

Actually, that's C, not C++.

And we will need to know what the code is supposed to do, and what it is doing before we can be of any help.


uhmm.. Thank You for explaining biggrin.gif

here it does.

1. It will print all the possible combinations/permutations of a word.

example:
Input: CAT
Output:
CTA
ACT
TCA
ATC
TAC

My only problem now. Is that when I entered a String with the same letters like. ACC (for example). It will still print the same. I don't want to print that. Instead Skip it and procede to the next. biggrin.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 06:20AM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month