Monday, April 30, 2012

C Program That Generate All Combination Using 1,2,3


Hello friends,in this program i generate all combinations such as 123,132,231,213,321,312 using only three numbers 1,2,3...please read the program carefully and if you tought that there is other better solution of this program than share with me.



#include<stdio.h>
#include<conio.h>
int main()
{
 int i,j,m,n;
 clrscr();
 j=2;
 for(i=1;i<=3;i++)
 {

  if(i==3)
  {
   m=i*100 + (j+1)*10 + (j+2);
   printf("\n%d",m);
   n=i*100 + (j+2)*10 + (j+1);
   printf("\n%d",n);
  }
  else if(i==1 || i==2)
  {
   m=i*100 + j*10 + j+i;
   printf("\n%d",m);
   n=i*100 + (j+i)*10 + j;
   printf("\n%d",n);
  }
  j--;
 }

 getch();
 return(0);
}



            Thanks Friends.....

No comments:

Post a Comment

Please Give Me Your Views

Popular Posts