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

C++Server Side ProgrammingProgramming

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.

## Example

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;
findEvenAndOddNumbers(n);
return 0;
}

## Output

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

Even: 999998
Odd: 999999

## Conclusion

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

Published on 09-Apr-2021 16:47:14