Given a positive integer n, round it to nearest whole number having zero as last digit.
Input : 4722 Output : 4720 Input : 38 Output : 40 Input : 10 Output: 10
Let’s round down the given number n to the nearest integer which ends with 0 and store this value in a variable a.
a = (n / 10) * 10. So, the round up n (call it b) is b = a + 10.
If n – a > b – n then the answer is b otherwise the answer is a.
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.
- Round the given number to nearest multiple of 10 | Set-2
- Nearest prime less than given number n
- Nearest greater number by interchanging the digits
- Round-off a number to a given number of significant digits
- Nearest prime number in the array of every array element
- Nth number whose sum of digit is multiple of 10
- Smallest N digit number which is a multiple of 5
- n'th multiple of a number in Fibonacci Series
- Check if a number is multiple of 5 without using / and % operators
- Number of triplets such that each value is less than N and each pair sum is a multiple of K
- Check whether a very large number of the given form is a multiple of 3.
- An efficient way to check whether n-th Fibonacci number is multiple of 10
- Reduce the number to minimum multiple of 4 after removing the digits
- Write an Efficient Method to Check if a Number is Multiple of 3
- Smallest multiple of N with exactly N digits in its Binary number representation
- Nearest element with at-least one common prime factor
- Replace all consonants with nearest vowels in a string
- Puzzle | Neighbors in a round table
- Pattern Printing question asked in CGI Coding Round
- Seating arrangement of n boys and girls alternatively around a round table
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.
Improved By : jit_t