Monday, 24 December 2012
The permutation of a three(3) digit number
Do you like this story?
The Program for the permutation of a three(3) digit number:
//the permutation of a three(3) digit number...
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l,m,len=0,num[3],n;
clrscr;
printf("enter any three digit number:");
scanf("%d",&k);
m=k;
while(m!=0)
{
m=m/10;
len++;
}
if(len==3)
{
num[0]=k/100;
num[1]=(k%100)/10;
num[2]=(k%100)%10;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(l=0;l<3;l++)
{
if(i!=j && j!=l && l!=i)
printf("%d%d%d \n",num[i],num[j],num[l]);
}
}
}
}
else
printf("you have entered a %d digit number.please make sure length is 3",len);
getch();
}
and the output is like:
//the permutation of a three(3) digit number...
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l,m,len=0,num[3],n;
clrscr;
printf("enter any three digit number:");
scanf("%d",&k);
m=k;
while(m!=0)
{
m=m/10;
len++;
}
if(len==3)
{
num[0]=k/100;
num[1]=(k%100)/10;
num[2]=(k%100)%10;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(l=0;l<3;l++)
{
if(i!=j && j!=l && l!=i)
printf("%d%d%d \n",num[i],num[j],num[l]);
}
}
}
}
else
printf("you have entered a %d digit number.please make sure length is 3",len);
getch();
}
and the output is like:
This post was written by: Franklin Manuel
Franklin Manuel is a professional blogger, web designer and front end web developer. Follow him on Twitter
Subscribe to:
Post Comments (Atom)
0 Responses to “The permutation of a three(3) digit number”
Post a Comment