Thread: Different digits in number

  1. #1
    Registered User
    Join Date
    Nov 2009

    Different digits in number

    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;
          tmp /= 10;
    for(i = 0; i < N; i++)
    if(A[i]) counter++;		
    printf("\n\nThere r %u different digits in the number %u\n",counter , n);

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    in front of my computer
    Why do you need pointer for that? It can be done using one loop only.

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior

    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    It is unclear what you are asking for. Four words "Different digits in number" is not a description of what you want your function to achieve.
    One thing for you to do would be to give us some sample inputs and outputs.
    E.g. Is this what you want?

    Input: 56361 Output: 5
    Input: 424002 Output: 6

    Or this ...

    Input: 56361 Output: 4
    Input: 424002 Output: 3

    Or something else ...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  2. Learning Memory, Ins and Outs?
    By Zoiked in forum C Programming
    Replies: 1
    Last Post: 08-27-2007, 04:43 PM
  3. numeric header - number of digits
    By Mario F. in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2006, 12:02 PM
  4. Count the number of vowels, consonants, digits etc.
    By kumar14878 in forum C Programming
    Replies: 3
    Last Post: 05-09-2005, 12:34 AM
  5. Extracting individual digits from a short
    By G'n'R in forum C Programming
    Replies: 9
    Last Post: 08-30-2001, 10:30 AM