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

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
RossRoss
Every question is just a happy little opportunity.
Chat with Ross
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi

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