Google Search

Custom Search

Sunday, February 14, 2010

Write a Program to Find Permutation

#include
#include
int lev=-1,n,val[50],a[50];
void main()
{
int i,j;
clrscr();
printf("Enter howmany numbers
");
scanf("%d",&n);
for(i=0;i
{
val[i]=0;
j=i+1;
scanf("%d",&a[j]);
}
visit(0);
getch();
}
visit(int k)
{
int i;
val[k]=++lev;
if(lev==n)
{
for(i=0;i
printf("%2d",a[val[i]]);
printf(" ");
}
for(i=0;i
if(val[i]==0)
visit(i);
lev--;
val[k]=0;
}

No comments: