I’m trying to write a function that’ll detect if a digit is found in a number:
// returns 1 if source contains num, 0 otherwise
int contains_num(source, num);
for example, contains_num(12345, 3) returns 1 and contains_num(12345, 6) returns 0.
I’m not sure how to go about solving this. Probably can’t use pointers, arrays and such.
Any ideas? thanks.
Since this is homework, I don’t want to give you the entire answer right away. Instead, I’ll ask a series of questions, and let you answer in the comments, so I’ll simply be guiding you to the correct answer rather than giving it to you outright.
So, you have a number, and you want to break it down into individual digits. Can you think of a way of extracting one digit from the number, say, the last one? Think about what each digit represents, and how you might be able to isolate one digit from the rest of them.