Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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.
Example
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;
}
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.
Advertisements
