Find the nearest integer - MATLAB Cody - MATLAB Central

Problem 1278. Find the nearest integer

Difficulty:Rate

Given a vector of integers and a real number find the closest integer.

EX:

>> a = [2 4 5 6 8 10];

>> b = 4.6;

>> nearestNumber(a,b)

ans=5

Solution Stats

52.13% Correct | 47.87% Incorrect
Last Solution submitted on Jul 01, 2025

Problem Comments

Solution Comments

Show comments
MATLAB EXPO 2025 Registration is Now Open! November 12 – 13, 2025
Registration is now open for MathWorks annual virtual event MATLAB EXPO 2025...
0
0

Problem Recent Solvers358

Suggested Problems

More from this Author16

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!