# Counting quantity of different digits

• 11-17-2009
cowa
Counting quantity of different digits
What I'm doing wrong . . .
I need to count quantity of different digits in number
for example 321123 : and output i want like that

There r 3 different digits in the number 321123

Code:

``` while(n)             {  dif=n%10;           n/=10;           if (dif=n%10)                   n/=10;           else           count++;           }           printf("\nThere r  ",count);           printf(" different digits in the number",n);```
• 11-17-2009
MK27
Code:

```#include <stdio.h> int main() {         int n=321123, copy = n, r, counts[10] = {0}, digits = 0;         while (copy) {                 r = copy%10;                 counts[r]++;                 copy /= 10;         }         for (r=0;r<10;r++) {                 if (counts[r]) {                         printf("%d %d's\n",counts[r],r);                         digits++;                 }         }         printf("%d contains %d different digits.\n",n,digits);         return 0; }```