Given a number N, the task is to find the digit of the given number N. If the number has two middle digits then print the first middle digit.
Input: N = 12345
Input: N = 98562
Approach: The middle digit of any number N can be given by .
The length(len) of the given Number can be calculated as .
If N = 12345
len = (int)log10(12345) + 1 = 5
First half of N = N/105/2 = N/102 = 123
Therefor middle digit of N = last digit of First half of N = (First half of N) % 10 = 123 % 10 = 3
Below code is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of N-digit numbers having digit XOR as single digit
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Find the remainder when First digit of a number is divided by its Last digit
- Largest number less than N with digit sum greater than the digit sum of N
- Count of Numbers in Range where first digit is equal to last digit of the number
- Last digit of a number raised to last digit of N factorial
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Check if frequency of each digit is less than the digit
- Count n digit numbers not having a particular digit
- Count numbers in a range with digit sum divisible by K having first and last digit different
- Find the Nth digit from right in base B of the given number in Decimal base
- Sum of middle row and column in Matrix
- Product of middle row and column in an odd square matrix
- Print the middle character of a string
- Find the maximum Even Digit Sum node in the given tree
- Find the missing digit x from the given expression
- Count numbers formed by given two digit with sum having given digits
- Find the Number which contain the digit d
- Find nth number that contains the digit k or divisible by k.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.