answersLogoWhite

0

To do this manually, you can simply read through the number, keeping a manual tally in your head.

If you are looking for an algorithm to do it for you, here is one method that would work in C, where "number" is the value being tested and "digit" is the digit we're counting:

...

int whole = (int)number;

number -= whole;

tally = 0;

while(whole != 0){

if(whole % 10 digit) tally++;

number -= (int)number;

}

printf("We counted %i digits occurrences of the digit %i\n", tally, digit);

...

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

ReneRene
Change my mind. I dare you.
Chat with Rene
JudyJudy
Simplicity is my specialty.
Chat with Judy
RossRoss
Every question is just a happy little opportunity.
Chat with Ross

Add your answer:

Earn +20 pts
Q: Find the number of occurrences of a digit in a number?
Write your answer...
Submit
Still have questions?
magnify glass
imp