Thursday, 24 July 2014

C program to generate possible combinations in a 3 digit positive number

/* Program to generate possible combinations in a 3 digit positive number */

#include<stdio.h>
#include<conio.h>
void main()
{
 int n,a[3],i=0,j,k;
 clrscr();
 printf("\nEnter a three digits number:");
 scanf("%d",&n);
 while(n)
 {
  a[i++]=n%10;
  n=n/10;
 }
 for(i=0;i<3;i++)
    {
for(j=0;j<3;j++)
  {
   for(k=0;k<3;k++)
 {
  if(i==j||j==k||k==i)
continue;
printf("\n%d%d%d",a[i],a[j],a[k]);
 }
   }
printf("\n");
    }
 getch();
}

No comments:

Post a Comment