# Largest Even and Odd N-digit numbers in Hexadecimal Number System

Given an integer N, the task is to find the largest even and odd N-digit numbers in Hexadecimal Number System.

Examples:

Input: N = 1
Output:
Even: E
Odd: F

Input: N = 2
Output:
Even: FE
Odd: FF

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: To get the largest number, the digits of the number have to be maximum possible. Since in the hexadecimal number system, the maximum digit is ‘F’. So, generate ‘F’ (N – 1) times and then append ‘E’ for even and ‘F’ for odd in the end.

Below is the implementation of the above approach:

## C++

 `// C++ implementation of the approach ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Function to print the largest n-digit even ` `// and odd numbers in hexadecimal number system ` `void` `findNumbers(``int` `n) ` `{ ` ` `  `    ``// Append 'F' (N - 1) times ` `    ``string ans = string(n - 1, ``'F'``); ` ` `  `    ``// Append 'E' for an even number ` `    ``string even = ans + ``'E'``; ` ` `  `    ``// Append 'F' for an odd number ` `    ``string odd = ans + ``'F'``; ` ` `  `    ``cout << ``"Even: "` `<< even << endl; ` `    ``cout << ``"Odd: "` `<< odd << endl; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `n = 2; ` ` `  `    ``findNumbers(n); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation of the approach ` `class` `GFG ` `{ ` ` `  `    ``// Function to print the largest n-digit even ` `    ``// and odd numbers in hexadecimal number system ` `    ``static` `void` `findNumbers(``int` `n) ` `    ``{ ` ` `  `        ``// Append 'F' (N - 1) times ` `        ``String ans = string(n - ``1``, ``'F'``); ` ` `  `        ``// Append 'E' for an even number ` `        ``String even = ans + ``'E'``; ` ` `  `        ``// Append 'F' for an odd number ` `        ``String odd = ans + ``'F'``; ` ` `  `        ``System.out.print(``"Even: "` `+ even + ``"\n"``); ` `        ``System.out.print(``"Odd: "` `+ odd + ``"\n"``); ` `    ``} ` ` `  `    ``private` `static` `String string(``int` `n, ``char` `c) ` `    ``{ ` `        ``String str = ``""``; ` `        ``for` `(``int` `i = ``0``; i < n; i++) ` `            ``str += c; ` `        ``return` `str; ` `    ``} ` ` `  `    ``// Driver code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``int` `n = ``2``; ` ` `  `        ``findNumbers(n); ` `    ``} ` `} ` ` `  `// This code is contributed by 29AjayKumar `

## Python3

 `# Python3 implementation of the approach  ` ` `  `# Function to print the largest n-digit even  ` `# and odd numbers in hexadecimal number system  ` `def` `findNumbers(n) : ` ` `  `    ``# Append 'F' (N - 1) times  ` `    ``ans ``=` `'F'``*``(n ``-` `1``);  ` ` `  `    ``# Append 'E' for an even number  ` `    ``even ``=` `ans ``+` `'E'``;  ` ` `  `    ``# Append 'F' for an odd number  ` `    ``odd ``=` `ans ``+` `'F'``;  ` ` `  `    ``print``(``"Even: "` `, even);  ` `    ``print``( ``"Odd: "` `, odd);  ` ` `  `# Driver code  ` `if` `__name__ ``=``=` `"__main__"` `: ` ` `  `    ``n ``=` `2``;  ` ` `  `    ``findNumbers(n);  ` ` `  `# This code is contributed by AnkitRai01 `

## C#

 `// C# implementation of the approach ` `using` `System; ` ` `  `class` `GFG ` `{ ` `  `  `    ``// Function to print the largest n-digit even ` `    ``// and odd numbers in hexadecimal number system ` `    ``static` `void` `findNumbers(``int` `n) ` `    ``{ ` `  `  `        ``// Append 'F' (N - 1) times ` `        ``String ans = strings(n - 1, ``'F'``); ` `  `  `        ``// Append 'E' for an even number ` `        ``String even = ans + ``'E'``; ` `  `  `        ``// Append 'F' for an odd number ` `        ``String odd = ans + ``'F'``; ` `  `  `        ``Console.Write(``"Even: "` `+ even + ``"\n"``); ` `        ``Console.Write(``"Odd: "` `+ odd + ``"\n"``); ` `    ``} ` `  `  `    ``private` `static` `String strings(``int` `n, ``char` `c) ` `    ``{ ` `        ``String str = ``""``; ` `        ``for` `(``int` `i = 0; i < n; i++) ` `            ``str += c; ` `        ``return` `str; ` `    ``} ` `  `  `    ``// Driver code ` `    ``public` `static` `void` `Main(String[] args) ` `    ``{ ` `        ``int` `n = 2; ` `  `  `        ``findNumbers(n); ` `    ``} ` `} ` ` `  `// This code is contributed by 29AjayKumar `

Output:

```Even: FE
Odd: FF
```

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.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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.

Improved By : AnkitRai01, 29AjayKumar

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.