By | 25.12.2016

# Check Number is Unique Number or Not

Write a C++ Program to Check Number is Unique Number or Not. Here’s simple C++ Program to Check Number is Unique Number or Not in C++ Programming Language.

## Numbers in C++

Normally, when we work with Numbers, we use primitive data types such as int, short, long, float and double, etc. The number data types, their possible values and number ranges have been explained while discussing C++ Data Types.

A unique number is a number in which no digit is repeated. For example: 25712 is not a unique number as 2 is repeated twice while 4512 is a unique number.

So in this article I am sharing the C++ program that check if a number is unique or not.

Here is source code of the C++ Program to Check Number is Unique Number or Not. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.

### SOURCE CODE : :

```/*  C++ Program to Check Number is Unique Number or Not  */

#include<iostream>
#include<stdlib.h>

using namespace std;

int main()
{
long num;
char str;
int a={0},flag=1,i=0;

cout<<"Enter any number :: ";
cin>>num;
itoa(num,str,10);    //convert number to character array

while(str[i]!='\0')
{
switch(str[i])
{
case '0':
a++;
break;
case '1':
a++;
break;
case '2':
a++;
break;
case '3':
a++;
break;
case '4':
a++;
break;
case '5':
a++;
break;
case '6':
a++;
break;
case '7':
a++;
break;
case '8':
a++;
break;
case '9':
a++;
break;
}
i++;
}

for(i=0;i<10;i++)
{
if(a[i]>1)
{
flag=0;
break;
}
}

if(flag)
cout<<"\nNumber is Unique.\n";
else
cout<<"\nNumber is Not Unique.\n";

return 0;
}```

### Output : :

```/*  C++ Program to Check Number is Unique Number or Not  */

Enter any number :: 12345

Number is Unique.

Process returned 0```

Above is the source code for C++ Program to Check Number is Unique Number or Not which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.

Article Rating
Subscribe
Notify of Inline Feedbacks Won’t compile. “itoa” (aprx line 14-16) undefined Just see my simple implementation too!!!
Just comment and like if you understand this!!!
#include <iostream>
using namespace std;
int main()
{
int a,dup,i,j=0;
bool flag;
cout<<“Enter a number: “;
cin>>a;
dup=a;
while(dup){
i[j]=dup%10;
dup/=10;
++j;
}
for(int k=0;k<j;k++){
for(int l=(k+1);l<j;l++){
if(i[k]==i[l]){
flag = false;
goto label;
}
}
}
cout<<“The given number “<<a<<” is a unique number”;
return 0;
label:
cout<<“The given number “<<a<<” is not a unique number”;
return 0;
}