Smallest Even number with N digits
Given a number N, the task is to find the smallest Even number with N digits.
Examples:
Input: N = 1 Output: 0 Input: N = 2 Output: 10
Approach:
Case 1 : If N = 1 then answer will be 0.
Case 2 : if N != 1 then answer will be (10^(N-1)) because the series of smallest even numbers will go on like, 0, 10, 100, 1000, 10000, 100000, …..
Below is the implementation of the above approach:
C++
// C++ implementation of the approach #include <bits/stdc++.h> using namespace std; // Function to return smallest even // number with n digits int smallestEven(int n) { if (n == 1) return 0; return pow(10, n - 1); } // Driver Code int main() { int n = 4; cout << smallestEven(n); return 0; } |
chevron_right
filter_none
Java
// Java implementation of the approach class Solution { // Function to return smallest even // number with n digits static int smallestEven(int n) { if (n == 1) return 0; return Math.pow(10, n - 1); } // Driver code public static void main(String args[]) { int n = 4; System.out.println(smallestEven(n)); } } |
chevron_right
filter_none
Python3
# Python3 implementation of # the approach # Function to return smallest # even number with n digits def smallestEven(n) : if (n == 1): return 0 return pow(10, n - 1) # Driver Code n = 4print(smallestEven(n)) # This code is contributed # by ihritik. |
chevron_right
filter_none
C#
// C# implementation of the approach using System; class Solution { // Function to return smallest even // number with n digits static int smallestEven(int n) { if (n == 1) return 0; return Math.pow(10, n - 1); } // Driver code public static void Main() { int n = 4; Console.Write(smallestEven(n)); } } |
chevron_right
filter_none
PHP
<?php // PHP implementation of the approach // Function to return smallest // even number with n digits function smallestEven($n) { if ($n == 1) return 0; return pow(10, $n - 1); } // Driver Code $n = 4; echo smallestEven($n); // This code is contributed // by ihritik. ?> |
chevron_right
filter_none
Output:
1000
Time Complexity: O(1).
Recommended Posts:
- Smallest even digits number not less than N
- Smallest odd digits number not less than N
- Smallest odd number with N digits
- Smallest number with at least n digits in factorial
- Smallest number with sum of digits as N and divisible by 10^N
- Find the kth smallest number with sum of digits as m
- Find the smallest number whose digits multiply to a given number n
- Smallest number k such that the product of digits of k is equal to n
- Immediate smallest number after re-arranging the digits of a given number
- Smallest number by rearranging digits of a given number
- Find the smallest positive number which can not be represented by given digits
- Smallest x such that 1*n, 2*n, ... x*n have all digits from 1 to 9
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Smallest multiple of 3 which consists of three given non-zero digits
- Smallest and Largest Palindrome with N Digits
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ihritik



