# Largest Even and Odd N-digit numbers

Given an integer **N**, the task is to find the largest even and odd N-digit numbers.**Examples:**

Input:N = 4Output:

Even = 9998

Odd = 9999Input:N = 2Output:

Even = 98

Odd = 99

Attention reader! All those who say programming isn't for kids, just haven't met the right mentors yet. Join the

Demo Class for First Step to Coding Course,specificallydesigned for students of class 8 to 12.The students will get to learn more about the world of programming in these

free classeswhich will definitely help them in making a wise career choice in the future.

**Approach:**

- Largest
**N-digit even number**will be**(10**because the series for different values of^{n}) – 2**N**will be**8, 98, 998, 9998, …..** - Similarly, largest
**N-digit odd number**will be**(10**for the series^{n}) – 1**9, 99, 999, 9999, …..**

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function to print the largest n-digit` `// even and odd numbers` `void` `findNumbers(` `int` `n)` `{` ` ` `int` `odd = ` `pow` `(10, n) - 1;` ` ` `int` `even = odd - 1;` ` ` `cout << ` `"Even = "` `<< even << endl;` ` ` `cout << ` `"Odd = "` `<< odd;` `}` `// Driver code` `int` `main()` `{` ` ` `int` `n = 4;` ` ` `findNumbers(n);` ` ` `return` `0;` `}` |

## Java

`// Java implementation of the approach` `class` `GFG {` ` ` `// Function to print the largest n-digit` ` ` `// even and odd numbers` ` ` `static` `void` `findNumbers(` `int` `n)` ` ` `{` ` ` `int` `odd = (` `int` `)Math.pow(` `10` `, n) - ` `1` `;` ` ` `int` `even = odd - ` `1` `;` ` ` `System.out.println(` `"Even = "` `+ even);` ` ` `System.out.print(` `"Odd = "` `+ odd);` ` ` `}` ` ` `// Driver code` ` ` `public` `static` `void` `main(String args[])` ` ` `{` ` ` `int` `n = ` `4` `;` ` ` `findNumbers(n);` ` ` `}` `}` |

## C#

`// C# implementation of the approach` `using` `System;` `class` `GFG {` ` ` `// Function to print the largest n-digit` ` ` `// even and odd numbers` ` ` `static` `void` `findNumbers(` `int` `n)` ` ` `{` ` ` `int` `odd = (` `int` `)Math.Pow(10, n) - 1;` ` ` `int` `even = odd - 1;` ` ` `Console.WriteLine(` `"Even = "` `+ even);` ` ` `Console.Write(` `"Odd = "` `+ odd);` ` ` `}` ` ` `// Driver code` ` ` `public` `static` `void` `Main()` ` ` `{` ` ` `int` `n = 4;` ` ` `findNumbers(n);` ` ` `}` `}` |

## Python3

`# Python3 implementation of the approach` `# Function to print the largest n-digit` `# even and odd numbers` `def` `findNumbers(n):` ` ` `odd ` `=` `pow` `(` `10` `, n) ` `-` `1` ` ` `even ` `=` `odd ` `-` `1` ` ` `print` `(` `"Even = "` `, even)` ` ` `print` `(` `"Odd = "` `, odd)` `# Driver code` `n ` `=` `4` `findNumbers(n)` `# This code is contributed by ihritik` |

## PHP

`<?php` `// PHP implementation of the approach` `// Function to print the largest n-digit` `// even and odd numbers` `function` `findNumbers(` `$n` `)` `{` ` ` `$odd` `= pow(10, ` `$n` `) - 1;` ` ` `$even` `= ` `$odd` `- 1;` ` ` `echo` `"Even = $even \n"` `;` ` ` `echo` `"Odd = $odd"` `;` `}` `// Driver code` `$n` `= 4 ;` `findNumbers(` `$n` `);` `// This code is contributed by ihritik` `?>` |

## Javascript

`<script>` ` ` `// Javascript implementation of the approach` ` ` ` ` `// Function to print the largest n-digit` ` ` `// even and odd numbers` ` ` `function` `findNumbers(n)` ` ` `{` ` ` `var` `odd = Math.pow(10, n) - 1;` ` ` `var` `even = odd - 1;` ` ` `document.write(` `"Even = "` `+ even+` `"<br>"` `);` ` ` `document.write(` `"Odd = "` `+ odd);` ` ` `}` ` ` ` ` `// Driver code` ` ` `var` `n = 4;` ` ` `findNumbers(n);` ` ` ` ` `// This code is contributed by rrrtnx.` ` ` `</script>` |

**Output:**

Even = 9998 Odd = 9999