# Largest Even and Odd N-digit numbers

Given an integer **N**, the task is to find the largest even and odd N-digit numbers.

**Examples:**

Input:N = 4

Output:

Even = 9998

Odd = 9999

Input:N = 2

Output:

Even = 98

Odd = 99

**Approach:**

- Largest
**N-digit even number**will be**(10**because the series for different values of^{n}) – 2**N**will be**8, 98, 998, 9998, …..** - Similarly, largest
**N-digit odd number**will be**(10**for the series^{n}) – 1**9, 99, 999, 9999, …..**

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to print the largest n-digit ` `// even and odd numbers ` `void` `findNumbers(` `int` `n) ` `{ ` ` ` `int` `odd = ` `pow` `(10, n) - 1; ` ` ` `int` `even = odd - 1; ` ` ` `cout << ` `"Even = "` `<< even << endl; ` ` ` `cout << ` `"Odd = "` `<< odd; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 4; ` ` ` `findNumbers(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `GFG { ` ` ` ` ` `// Function to print the largest n-digit ` ` ` `// even and odd numbers ` ` ` `static` `void` `findNumbers(` `int` `n) ` ` ` `{ ` ` ` `int` `odd = (` `int` `)Math.pow(` `10` `, n) - ` `1` `; ` ` ` `int` `even = odd - ` `1` `; ` ` ` `System.out.println(` `"Even = "` `+ even); ` ` ` `System.out.print(` `"Odd = "` `+ odd); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `n = ` `4` `; ` ` ` `findNumbers(n); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` `class` `GFG { ` ` ` ` ` `// Function to print the largest n-digit ` ` ` `// even and odd numbers ` ` ` `static` `void` `findNumbers(` `int` `n) ` ` ` `{ ` ` ` `int` `odd = (` `int` `)Math.Pow(10, n) - 1; ` ` ` `int` `even = odd - 1; ` ` ` `Console.WriteLine(` `"Even = "` `+ even); ` ` ` `Console.Write(` `"Odd = "` `+ odd); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `n = 4; ` ` ` `findNumbers(n); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to print the largest n-digit ` `# even and odd numbers ` `def` `findNumbers(n): ` ` ` ` ` `odd ` `=` `pow` `(` `10` `, n) ` `-` `1` ` ` `even ` `=` `odd ` `-` `1` ` ` `print` `(` `"Even = "` `, even) ` ` ` `print` `(` `"Odd = "` `, odd) ` ` ` `# Driver code ` `n ` `=` `4` `findNumbers(n) ` ` ` `# This code is contributed by ihritik ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to print the largest n-digit ` `// even and odd numbers ` `function` `findNumbers(` `$n` `) ` `{ ` ` ` `$odd` `= pow(10, ` `$n` `) - 1; ` ` ` `$even` `= ` `$odd` `- 1; ` ` ` `echo` `"Even = $even \n"` `; ` ` ` `echo` `"Odd = $odd"` `; ` `} ` ` ` `// Driver code ` `$n` `= 4 ; ` `findNumbers(` `$n` `); ` ` ` `// This code is contributed by ihritik ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Even = 9998 Odd = 9999

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.

## Recommended Posts:

- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Smallest and Largest sum of two n-digit numbers
- Largest Even and Odd N-digit numbers of base B
- Largest palindrome which is product of two N-digit numbers : Set 2
- Largest and Smallest N-digit Octal Numbers
- Largest and Smallest N-digit Hexadecimal Numbers
- Largest N digit number divisible by given three numbers
- Largest palindrome which is product of two n-digit numbers
- Count of triplets of numbers 1 to N such that middle element is always largest
- Sum and product of k smallest and k largest prime numbers in the array
- Sum and product of k smallest and k largest composite numbers in the array
- Largest Even and Odd N-digit numbers in Octal Number System
- Largest number by which given 3 numbers should be divided such that they leaves same remainder
- Largest of two distinct numbers without using any conditional statements or operators
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Find the length of largest subarray in which all elements are Autobiographical Numbers
- Fill the missing numbers in the array of N natural numbers such that arr[i] not equal to i
- Permutation of numbers such that sum of two consecutive numbers is a perfect square
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- Numbers less than N which are product of exactly two distinct prime numbers

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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.