Largest Even and Odd N-digit numbers Last Updated : 22 Jun, 2022 Comments Improve Suggest changes Like Article Like Report 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 = 9999Input: N = 2 Output: Even = 98 Odd = 99 Approach: Largest N-digit even number will be (10n) - 2 because the series for different values of N will be 8, 98, 998, 9998, .....Similarly, largest N-digit odd number will be (10n) - 1 for the series 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; } 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); } } 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); } } 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 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 ?> JavaScript <script> // Javascript implementation of the approach // Function to print the largest n-digit // even and odd numbers function findNumbers(n) { var odd = Math.pow(10, n) - 1; var even = odd - 1; document.write("Even = " + even+"<br>"); document.write("Odd = " + odd); } // Driver code var n = 4; findNumbers(n); // This code is contributed by rrrtnx. </script> Output: Even = 9998 Odd = 9999 Time Complexity: O(log n) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Largest and Smallest N-digit Octal Numbers S spp____ Follow Improve Article Tags : Mathematical DSA school-programming number-theory Practice Tags : Mathematicalnumber-theory Similar Reads Largest Even and Odd N-digit numbers of base B Given an integer N and base B, the task is to find the largest Even and Odd N-digit numbers of Base B in decimal form. Examples: Input: N = 2, B = 5 Output: Even = 24 Odd = 23 Explanation: Largest Even Number of 2 digits in base 5 = 44 which is 24 in decimal form. Largest Odd Number of 2 digits in b 7 min read Largest Even and Odd N-digit numbers in Octal Number System Given an integer N, the task is to find the largest even and odd N-digit numbers in Octal Number System.Examples: Input: N = 4 Output: Even : 7776 Odd : 7777Input: N = 2 Output: Even : 76 Odd : 77 Approach: To get the largest number, the digits of the number have to be maximum possible. Since in the 4 min read Largest and Smallest N-digit Octal Numbers Given an integer N, the task is to find the smallest and largest N-digit numbers in Octal Number System. Examples: Input: N = 4 Output: Largest: 7777 Smallest: 1000 Input: N = 2 Output: Largest: 77 Smallest: 10 Approach: The following steps can be followed to compute the required answer: Largest Num 5 min read Largest and Smallest N-digit Octal Numbers Given an integer N, the task is to find the smallest and largest N-digit numbers in Octal Number System. Examples: Input: N = 4 Output: Largest: 7777 Smallest: 1000 Input: N = 2 Output: Largest: 77 Smallest: 10 Approach: The following steps can be followed to compute the required answer: Largest Num 5 min read Largest and Smallest N-digit Octal Numbers Given an integer N, the task is to find the smallest and largest N-digit numbers in Octal Number System. Examples: Input: N = 4 Output: Largest: 7777 Smallest: 1000 Input: N = 2 Output: Largest: 77 Smallest: 10 Approach: The following steps can be followed to compute the required answer: Largest Num 5 min read Largest and Smallest N-digit Hexadecimal Numbers Given an integer N, the task is to find the smallest and largest N-digit numbers Hexa-Decimal Number System. Examples: Input: N = 4 Output: Largest: FFFF Smallest: 1000 Input: N = 2 Output: Largest: FF Smallest: 10 Approach: The following steps can be followed to complete the required answer: Larges 5 min read Like