Program to find the possibilities of Number Inputs..... Very Good Program

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{
long n, x, arr[10],i=0,count=0, size=0, temp, start, stop;
long tempArr[10],flag[10]={0};
clrscr();

cout<<"Enter N : ";
cin>>n;
x=n;
//Loop for getting the length of digits.
while(x)
{
temp=x%10;
size++;
arr[i++]=temp;
x/=10;
}
start=pow(10,size-1);
stop=pow(10,size);

//Loop for printing the range of length possibilities.
for(i=start;i<stop;i++)
{
long temp=i;
for(int j=0;j<size;j++)
{
tempArr[j]=temp%10;
temp=temp/10;
}
for(j=0;j<size;j++)
{
flag[j]=0;
for(int k=0;k<size;k++)
{
if(arr[j]==tempArr[k])
flag[j]+=1;
}
}
int f=0;
for(j=0;j<size;j++)
{
if(flag[j]!=1)
{
f++;
break;
}
}
if(!f)
{
cout<<i<<"\t";
count++;
}
}
cout<<"\nThere are "<<count<<" possibilities\n";
getch();
}


/*
Output:
Enter N : 1479
1479    1497    1749    1794    1947    1974    4179    4197    4719    4791
4917    4971    7149    7194    7419    7491    7914    7941    9147    9174
9417    9471    9714    9741
There are 24 possibilities
*/



No comments

Post your comments

Powered by Blogger.