C Language Program To Display Permutation Of Given Numbers


#include<stdio.h>
#include<stdlib.h>
int lev=-1,n,val[50],a[50];
void main()
{
 int i,j;
 clrscr();
 printf("Enter Numbers to make Permutaion");
 scanf("%d",&n);
 for(i=0;i<n;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<n;i++)
  printf("%2d",a[val[i]]);
  printf("\t");
 }
 for(i=0;i<n;i++)
 if(val[i]==0)
 visit(i);
 lev--;
 val[k]=0;
}


Output:
Enter Numbers to make Permutaion4
1
2
3
4
 1 2 3 4         1 2 4 3         1 3 2 4         1 4 2 3         1 3 4 2
 1 4 3 2         2 1 3 4         2 1 4 3         3 1 2 4         4 1 2 3
 3 1 4 2         4 1 3 2         2 3 1 4         2 4 1 3         3 2 1 4
 4 2 1 3         3 4 1 2         4 3 1 2         2 3 4 1         2 4 3 1
 3 2 4 1         4 2 3 1         3 4 2 1         4 3 2 1


Contact:
Mr. Roshan P. Helonde
Mobile: +91-7276355704
WhatsApp: +91-7276355704
Email: roshanphelonde@rediffmail.com
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *