C++ Program to Check Whether a Number is Unique Number or Not

A unique number is a number in which no digit is repeated. For example: 102452 is not a unique number as 2 is repeated twice while 2374 is a unique number. So in this article I am sharing the C++ program that check if a number is unique or not.

 

 
Output
C++ Program to Check Whether a Number is Unique Number or Not
If you have any other solution for this problem then you can share it with us by commenting below.

4 thoughts on “C++ Program to Check Whether a Number is Unique Number or Not”

  1. You could just sort this string, and check with one for(). Like this:

    #include
    #include
    #include

    int main() {
    char num[100];
    scanf("%s", num); // read number as string
    int len = strlen(num);
    std::sort(num, num+len); // sort string
    for (int i = 1; i < len; i++) {
    if (num[i-1] == num[i]) {
    printf("nNumber is Not Unique");
    return 0;
    }
    }
    printf("nNumber is Unique");
    return 0;
    }

  2. József Kerékgyártó

    I just did it. Hope you like it 🙂

    bool is_unique_number(char * snumber) {
    for (int j = 0; j <= 9; j++) {
    int counter = 0;
    for (int i = 0; snumber[i] != ''; i++)
    if ((snumber[i] – '0') == j)
    counter++;
    if (counter > 1)
    return false;
    }
    return true;
    }

  3. Please start a YouTube channel for breif knowledge…. Some of the starting programmers like me had to face a lot of difficulty in understanding!

Leave a Comment

Your email address will not be published. Required fields are marked *