//C++ unique number program
/*unique No are those No in which no digit is
repeated e.g 123,321 and 12345 are unique Nos*/
#include <iostream>
using namespace std;
int main()
{
//initialize entire array of size 10 to zero
int arry[10]={0};
int num,rem,j=0,num1;
cout<<"Enter number : ";
cin>>num;
num1=num;
while (num!=0)
{
rem=num%10;
//to check all digits of No
switch(rem){
case 0:
++arry[rem];
break;
case 1:
++arry[rem];
break;
case 2:
++arry[rem];
break;
case 3:
++arry[rem];
break;
case 4:
++arry[rem];
break;
case 5:
++arry[rem];
break;
case 6:
++arry[rem];
break;
case 7:
++arry[rem];
break;
case 8:
++arry[rem];
break;
case 9:
++arry[rem];
break;
default:
cout<<"Enter a valid number "<<endl;
}
num=num/10;
}
for (int i=0;i<10;i++)
{
if (arry[i]>1)
{
j++;
}
}
if (j==0)
{
cout<<"The number "<<num1<<" is unique "<<endl;
}
else
cout<<"The number "<<num1<<" is not unique "<<endl;
return 0;
}
No comments:
Post a Comment