Your answer is dependent on the base a number is represented in. For example, the number 255 contains 5 when written in base 10, but in base 16, it does not. Your base seems to be 10.
So what you want to do is to look at the last digit of a number, and see if it is the digit you want. The last digit can be easily found using the modulo operator (%
). If it is the digit you want, you're done. If not, and if there are more digits, you can discard the last digit and repeat the process again for the number obtained by dividing the original number by 10 and discarding the fractional part. In C, the division operator, /
, does this for you automatically if both the operands of it are of integer type.
When you run out of digits because division gives you 0, you are sure that the number doesn't contain the digit you wanted.