Number of n digit numbers that do not contain 9 Last Updated : 29 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Given a number n, find how many n digit number can be formed that does not contain 9 as it's digit.Examples: 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: C++ // CPP program to find number of n // digit numbers that do not // contain 9 as it's digit #include <bits/stdc++.h> using namespace std; // function to find number of // n digit numbers possible int totalNumber(int n) { return 8*pow(9, n - 1); } // driver function int main() { int n = 3; cout << totalNumber(n); return 0; } Java // Java program to find number of // n digit numbers that do not // contain 9 as it's digit import java.io.*; public class GFG { // function to find number of // n digit numbers possible static int totalNumber(int n) { return 8 * (int)Math.pow(9, n - 1); } // Driver Code static public void main (String[] args) { int n = 3; System.out.println(totalNumber(n)); } } // This code is contributed by vt_m. Python3 # python program to find number of n # digit numbers that do not # contain 9 as it's digit # function to find number of # n digit numbers possible def totalNumber(n): return 8 * pow(9, n - 1); # driver function n = 3 print(totalNumber(n)) # This code is contributed by Sam007 C# // C# program to find number of // n digit numbers that do not // contain 9 as it's digit using System; public class GFG { // function to find number of // n digit numbers possible static int totalNumber(int n) { return 8 * (int)Math.Pow(9, n - 1); } // Driver Code static public void Main () { int n = 3; Console.WriteLine(totalNumber(n)); } } // This code is contributed by vt_m. php <?php // php program to find number of n // digit numbers that do not // contain 9 as it's digit // function to find number of // n digit numbers possible function totalNumber($n) { return 8 * pow(9, $n - 1); } // driver function $n = 3; print(totalNumber($n)) // This code is contributed by Sam007 ?> JavaScript <script> // Javascript program to find number of // n digit numbers that do not // contain 9 as it's digit // function to find number of // n digit numbers possible function totalNumber(n) { return 8 * Math.pow(9, n - 1); } // Driver code let n = 3; document.write(totalNumber(n)); // This code is contributed by code_hunt. </script> Output648 Time Complexity: O(log n)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Count of all N digit numbers such that num + Rev(num) = 10^N - 1 D Dibyendu Roy Chaudhuri Improve Article Tags : DSA number-digits Similar Reads Total number of non-decreasing numbers with n digits A number is non-decreasing if every digit (except the first one) is greater than or equal to the previous digit. For example, 223, 4455567, 899, are non-decreasing numbers.So, given the number of digits n, you are required to find the count of total non-decreasing numbers with n digits.Examples:Inpu 11 min read Count numbers that does not contain digit N in given range Given integers, N, L, and R, the task is to find the number of integers in the range L to R that does not contain the digit N. print the answer modulo 109 + 7. ( L ? R ? 101000000) Examples: Input: N = 5, L = 1, R = 10Output: 9Explanation: excluding all 5 others from 1 to 10 will be included in the 14 min read Count of all N digit numbers such that num + Rev(num) = 10^N - 1 Given an integer N, the task is to find the count of all N digit numbers such that num + Rev(num) = 10N - 1Examples: Input: N = 2 Output: 9 All possible numbers are 18 + 81 = 99 27 + 72 = 99 36 + 45 = 99 45 + 54 = 99 54 + 45 = 99 63 + 54 = 99 72 + 27 = 99 81 + 18 = 99 90 + 09 = 99 Input: N = 4 Outpu 4 min read Nth natural number after removing all numbers consisting of the digit 9 Given a positive integer N, the task is to find the Nth natural number after removing all the natural numbers containing digit 9.Examples:Input: N = 8Output: 8Explanation:Since 9 is the first natural number that contains the digit 9 and is the 9th natural number, therefore, no removal required to fi 8 min read Count of N-digit numbers with all distinct digits Given an integer N, the task is to find the count of N-digit numbers with all distinct digits.Examples: Input: N = 1 Output: 9 1, 2, 3, 4, 5, 6, 7, 8 and 9 are the 1-digit numbers with all distinct digits.Input: N = 3 Output: 648 Naive Approach: If N > 10 i.e. there will be atleast one digit whic 7 min read Number of n digit stepping numbers Given n, find count of n digit Stepping numbers. A number is called stepping number if all adjacent digits have an absolute difference of 1. 321 is a Stepping Number while 421 is not. Examples :Â Â Input : 2 Output : 17 Explanation: The numbers are 10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 13 min read Like