Largest Even and Odd N-digit numbers in C++

In this tutorial, we are going to write a program that finds the largest even and odd number of n digits number.

Let's see the steps to solve the problem.

  • Initialise the number n.
  • The largest odd number is pow(10, n) - 1.
  • The largest even number is odd - 1.


Let's see the code.

 Live Demo

#include <bits/stdc++.h>
using namespace std;
void findEvenAndOddNumbers(int n) {
   int odd = pow(10, n) - 1;
   int even = odd - 1;
   cout << "Even: " << even << endl;
   cout << "Odd: " << odd << endl;
int main() {
   int n = 6;
   return 0;


If you run the above code, then you will get the following result.

Even: 999998
Odd: 999999


If you have any queries in the tutorial, mention them in the comment section.