-2

This program generates different combinations of a number or a string as given by the user.just a simple implementation of arrays.

Comments
this is pure dogshit.
/////////////////////////////////////////////////////////////////
//////     This program will generate all the possible ///////
/////        arrangement of the string or number      //////
//////////////////////////////////////////////////////////////


#include<stdio.h>
#include<string.h>
# include<alloc.h>
#include<conio.h>


///////////////////////////////////////////////////////
/////////    Programmer : Harsh Chandra    ///////
/////////////////////////////////////////////////////



	void swap(char*,int);
	void gotoloop(char*,int);

	void main()
	{
		char *ch;
		int i,j,k,l;
		ch=(char*)malloc(20);
		clrscr();
		printf("Enter the string\n");
		gets(ch);

		l=strlen(ch);
		gotoloop(ch,l);

		return 0;
	}

	void gotoloop(char *ch,int l)
	{
		int i,k;
		k=l;

		if(l<=1) 
                return;


		for(i=0;i<k;i++)
		{
			swap(ch,k);
			l--;
			gotoloop(ch,l);
			l++;
			if(k==2)
			printf("\n%s ",ch);
		}

		 }


	void swap(char *ch,int r)

	{
		char c;
		int i;

		c=ch[r-1];
		for(i=r-1;i>0;i--)
			ch[i]=ch[i-1];
		ch[0]=c;
	}

11
Contributors
15
Replies
19
Views
12 Years
Discussion Span
Last Post by Nick Evan
1

# include<alloc.h> - is nonstandard
#include<conio.h> - is nonstandard
void main() - is incorrect
ch=(char*)malloc(20) - the cast is unnecessary, you should check the return value
clrscr(); - nonstandard function
gets(ch); - never use gets()!
return 0; - returning a value from a void function?

-2
/* Non-recursive Permutation generator
 By : Mudit Aggarwal  */

#include<stdio.h>
#include<string.h>
void main()
{
        /* String */
        char ch[]="123";

        char temp;
        int len = strlen(ch), count=1;
        int i, start=len-2, end=len-1;

       // Finds permutation count
        for(i=1; i<=len; i++)
                count *= i;

        for(i=0; i<count; i++)
        {
                //swap characters
                temp=ch[end];
                ch[end]=ch[start];
                ch[start]=temp;

                printf("%s\n",ch);

                start--;
                end--;
                if(start<0)
                {
                        start=len-2;
                        end=len-1;
                }
        }

        getchar();
}

Edited by mike_2000_17: Fixed formatting

Comments
neg rep for bumping a 5 year old thread, and posting snippet without code tags. the fact that you used void main makes me doubt it even works. can't say i care to find out.
0

||=== perm, Debug ===|
|warning: return type of 'main' is not `int'|
||=== Build finished: 0 errors, 1 warnings ===|

i wonder why your program gives me warning....

-1

Default return type of main is int. So, its throwing a warning as it is void in program. ( Sorry..my bad). however, program will run.

Make it :
int main()
{
// code
return 1;
}

-1

Mudit agarwal I implemented your program in CSharp it works for ok for abc but not for 'abcd' or 'abcde'. if abcd isgiven as input all i get is 12 strings instead of 24. The recursive approach is more cleaner and modular.

2

the entire thread, starting from the very first snippet by OP, is crap.

code snippets should not be allowed to be created by anyone with less than 100 posts.

0

unfortunately, the reality is that the snippet quality around here tends to be amateurish if not downright garbage.

so it actually IS "up to snippet level".

and that's the real problem

-2

permutation in increasing order like - for {a,t,c,s,w,i} the permutations will be

acis
acit
aciw..so on

-2

need a code somewhat like this

set {a,t,c,i,w,s}
need to find all possible permutations of length 4 out of the above 6 chars,and each of the permutations must be in alphabetical order.

Comments
Nope
Bump bump bump, only for a stupid gimmethcodez request.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.