This program generates different combinations of a number or a string as given by the user.just a simple implementation of arrays.
Permutations Of A Number Or String
jephthah commented: this is pure dogshit. -1
/////////////////////////////////////////////////////////////////
////// 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;
}
anurag_wizards 0 Newbie Poster
muraya 0 Newbie Poster
Dave Sinkula 2,398 long time no c Team Colleague
ainakya 0 Newbie Poster
muditAggarwal -1 Newbie Poster
jephthah commented: 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. -1
jephthah 1,888 Posting Maven
muditAggarwal -1 Newbie Poster
jephthah 1,888 Posting Maven
kawareness1 0 Newbie Poster
jephthah 1,888 Posting Maven
Adak 419 Nearly a Posting Virtuoso
jephthah 1,888 Posting Maven
scuba-duba -3 Newbie Poster
scuba-duba -3 Newbie Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.