Largest Even and Odd N | C ++ implementation of the above approach ; Function to print the largest N - digit even and odd numbers of base B ; Initialise the Number ; If Base B is even , then B ^ n will give largest Even number of N + 1 digit ; To get even number of N digit subtract 2 from B ^ n ; To get odd number of N digit subtract 1 from B ^ n ; If Base B is odd , then B ^ n will give largest Odd number of N + 1 digit ; To get even number of N digit subtract 1 from B ^ n ; To get odd number of N digit subtract 2 from B ^ n ; Driver 's Code ; Function to find the numbers
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findNumbers ( int n , int b ) { int even = 0 , odd = 0 ; if ( b % 2 == 0 ) { even = pow ( b , n ) - 2 ; odd = pow ( b , n ) - 1 ; } else { even = pow ( b , n ) - 1 ; odd = pow ( b , n ) - 2 ; } cout << " Even ▁ Number ▁ = ▁ " << even << ' ' ; cout << " Odd ▁ Number ▁ = ▁ " << odd ; } int main ( ) { int N = 2 , B = 5 ; findNumbers ( N , B ) ; return 0 ; }