How can I do it - with pointer and only one loop ?

for exmpl function - unsigned int dif(const char *str)

``````counter = 0;
for(i = 0; i < N; i++)
A[i] = 0;
do
{
A[tmp % 10]++;
tmp /= 10;
}
while(tmp);
for(i = 0; i < N; i++)
if(A[i])counter++;
printf("\n\nThere r %u different digits in the number %u\n",counter , n);``````
3
Contributors
4
Replies
7
Views
8 Years
Discussion Span
Last Post by gerard4143

u dint define tmp... wat is tmp actually??

I read this posting a few times and I'm at a loss..Do you mean if you have a number say:

unsigned int myint = 87456;

do you want to extract from it 8 - 7 - 4 - 5 - 6?

Edited by gerard4143: n/a

No, I want like that 87456 - we have 5 different digits (It's all what I want)

one more exmp - number 113452266 - we have 6 different digts
I did it with two loops but i don't know - how to do it with 1 loop and pointers :)

No, I want like that 87456 - we have 5 different digits (It's all what I want)

one more exmp - number 113452266 - we have 6 different digts
I did it with two loops but i don't know - how to do it with 1 loop and pointers :)

so you have a number defined as

unsigned int myint = 113452266;

and you want to extract the number of unique digits from myint?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.