Given an integer N, the task is to find the product of N with its largest odd digit. If there is no odd digit in N then print -1 as the output.
The largest odd digit in 12345 is 5 and 12345 * 5 = 61725
Approach: Traverse through all the digits of N and set maxOdd = -1, if current digit is odd and > maxOdd then update maxOdd = current digit.
If in the end, maxOdd = -1 then print -1 else print N * maxOdd.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Largest palindrome which is product of two n-digit numbers
- Largest palindrome which is product of two N-digit numbers : Set 2
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Largest number less than N with digit sum greater than the digit sum of N
- Largest Even and Odd N-digit numbers
- Digit - Product - Sequence
- Largest Even and Odd N-digit numbers of base B
- Largest K digit number divisible by X
- Find the largest N digit multiple of N
- Largest value of x such that axx is N-digit number of base b
- Largest and smallest digit of a number
- Largest N digit number in Base B
- Smallest and Largest sum of two n-digit numbers
- Largest even digit number not greater than N
- First digit in product of an array of numbers
- Largest and Smallest N-digit Hexadecimal Numbers
- Smallest and Largest N-digit perfect squares
- Smallest and Largest N-digit perfect cubes
- Largest N digit number divisible by given three numbers
- C++ Program for Largest K digit number divisible by X
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.