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; ` `} ` |

*chevron_right*

*filter_none*

## 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. ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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. ` |

*chevron_right*

*filter_none*

## 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 ` `?> ` |

*chevron_right*

*filter_none*

Output:

648

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 contribute@geeksforgeeks.org. 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.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.