My challenge is to output the total number of five-digit numbers that have a digit 5, but no digits 8. My only two answers so far have been 0, or 90000. Can anyone help me? (Yes, I know the answer, but I'd like to know how to use if/else statements to achieve said answer, which is 26281)
If zero is allowed as the leading digit of the five digit number (ie. 00001 is a five digit number),
number of five-digit numbers without 8 == 9^5 == 59049
number of five-digit numbers without 8, and without 5 == 8^5 == 32768
number of five-digit numbers without 8, and with 5 == 59049 - 32768 == 26281
Otherwise ( 00001 is not a five digit number),
number of five-digit numbers without 8 == 8 * 9^4 == 52488
number of five-digit numbers without 8, and without 5 == 7 * 8^4 == 28672
number of five-digit numbers without 8, and with 5 == 52488 - 28672== 26281 == 23816