- Related Questions & Answers
- Product of N with its largest odd digit in C
- Largest even digit number not greater than N in C++
- Even numbers at even index and odd numbers at odd index in C++
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1 in C++
- Largest N digit number divisible by given three numbers in C++
- Finding all the n digit numbers that have sum of even and odd positioned digits divisible by given numbers - JavaScript
- Find even odd index digit difference - JavaScript
- Count rotations of N which are Odd and Even in C++
- Count n digit numbers not having a particular digit in C++
- Largest number less than N with digit sum greater than the digit sum of N in C++
- N consecutive odd numbers JavaScript
- Adding only odd or even numbers JavaScript
- Odd Even Jump in C++
- Print all n-digit strictly increasing numbers in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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.

#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; }

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.

Advertisements