Given a number n, find how many n digit number can be formed that does not contain 9 as it’s digit.
Input : 1 Output : 8 Explanation : Except 9, all numbers are possible Input : 2 Output : 72 Explanation : Except numbers from 90 - 99 and all two digit numbers that does not end with 9 are possible.
Total numbers of n digit number that can be formed will be 9*10^(n-1) as except first position all digits can be filled with 10 numbers (0-9). If a digit 9 is eliminated from the list then total number of n digit number will be 8*9^(n-1).
Below is the implementation of above idea:
This article is contributed by Dibyendu Roy Chaudhuri. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Count of Numbers in Range where first digit is equal to last digit of the number
- Number of occurrences of 2 as a digit in numbers from 0 to n
- Number of n digit stepping numbers
- Sum of n digit numbers divisible by a given number
- Largest N digit number divisible by given three numbers
- Count n digit numbers divisible by given number
- Smallest n digit number divisible by given three numbers
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Largest Even and Odd N-digit numbers in Octal Number System
- Print all K digit repeating numbers in a very large number
- Check whether a number can be expressed as a product of single digit numbers
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Count numbers with difference between number and its digit sum greater than specific value
- Number of n digit stepping numbers | Space optimized solution
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Count n digit numbers not having a particular digit
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Find the remainder when First digit of a number is divided by its Last digit
- Largest number less than N with digit sum greater than the digit sum of N
- Last digit of a number raised to last digit of N factorial