I really wonder why this code does not work

+1 Hayden Kuk · November 23, 2015

#include
#include
#include

int main()
{
    bool digit_seen[10] = {false};
    int digit_rpd[] = {0,1,2,3,4,5,6,7,8,9};
    int digit, i;
    long n;

    printf("Enter the number : ");
    scanf("%ld", &n);

    while (n > 0)
    {
        digit = n %10;
        if (digit_seen[digit])
            break;
        digit_seen[digit] = true;
        n /= 10;
    }
    if (n > 0)
        {
            printf("Repeated digit\n");
            printf("Repeated digits : ");
            for(i = 0; i < 10; i++)
           {
               if(digit_seen[i] = true)
               {
                   printf("%d, ", digit_rpd[i]);
               }

           };
           printf("\n");
        }
    else
        {printf("No repeated digit\n");}

    return 0;
}


I have created a code that checks if the number entered has repeated digits and repeated number if there is any,
but
checking repeated numbers that appeared does not work properly, why?

Post a Reply

Replies

Oldest  Newest  Rating
+1 Dan P · November 23, 2015
Hi Hayden,

Are you trying to write a program that tells you if a number is repeated in another number.

For example, in 1239990 the number 9 is repeated 3 times?
+1 c student · November 24, 2015
first thing's first, there's an error on this line
if(digit_seen[i] = true)
  • 1

C

107,280 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator