Problem 55230. Find Closest Constant
Given a number x, return the value that is closest to x from this list of constants: 0, 1, , e, π, (also known as τ).
For example:
c = closestconst(1.5)
c =
1.4142
c = closestconst(2.5)
c =
2.7183
c = closestconst(50)
c =
6.2832
c = closestconst(-10)
c =
0
If x is equally close to two values (eg ), you can return either value (so either 1 or would be correct in this example).
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers458
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15529 Solvers
-
Find state names that end with the letter A
1175 Solvers
-
17102 Solvers
-
5343 Solvers
-
651 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!