Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Program For All Combination of the Given String in C

This Programs Explains About the all the combinations of the Given String
For example:
If the Given String is ICON
The Possible Combinations are
ICON
ICNO
IOCN
IONC
INCO
INOC
CION
CINO
COIN
CONI
CNIO
CNOI
OICN
OINC
OCIN
OCNI
ONIC
ONCI
NICO
NIOC
NCIO
NCOI
NOIC
NOCI
#include<stdio.h>

#include<string.h>

//char digits[]="0123456789";
char digits[10][5]={"ICON","CREW","FARM","OILY","CHOP","ARID","FUND","WAIT","GNAT","TEAR"};

char str[10];
int top=0;

void push(char a)
{
    str[top++]=a;
}

char pop()
{
    return(str[--top]);
}

void generate(char dig[15],int n)
{
    int i;
    char dig2[15];
    if(n==0)
    {
        push('\0');
        printf("\n %s",str);
        pop();
    }
    else
    {

        for(i=0;dig[i]!='\0';i++)
        {
            if(dig[i]!=' ')
            {
                strcpy(dig2,dig);
                push(dig[i]);
                dig2[i]=' ';
                generate(dig2,n-1);
                pop();
            }
        }
    }
}

void main()
{
    int i;

    for(i=0;i<10;i++)
    {
       
        generate(digits[i],4);
        
    }
}


ICON
ICNO
IOCN
IONC
INCO
INOC
CION
CINO
COIN
CONI
CNIO
CNOI
OICN
OINC
OCIN
OCNI
ONIC
ONCI
NICO
NIOC
NCIO
NCOI
NOIC
NOCI
CREW
CRWE
CERW
CEWR
CWRE
CWER
RCEW
RCWE
RECW
REWC
RWCE
RWEC
ECRW
ECWR
ERCW
ERWC
EWCR
EWRC
WCRE
WCER
WRCE
WREC
WECR
WERC
FARM
FAMR
FRAM
FRMA
FMAR
FMRA
AFRM
AFMR
ARFM
ARMF
AMFR
AMRF
RFAM
RFMA
RAFM
RAMF
RMFA
RMAF
MFAR
MFRA
MAFR
MARF
MRFA
MRAF
OILY
OIYL
OLIY
OLYI
OYIL
OYLI
IOLY
IOYL
ILOY
ILYO
IYOL
IYLO
LOIY
LOYI
LIOY
LIYO
LYOI
LYIO
YOIL
YOLI
YIOL
YILO
YLOI
YLIO
CHO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