top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

C program to find closest items of given number from array ?

+4 votes
1,394 views

Say you are given an array and u need to find out the closest number from the array for a given number. Please help me.

posted Oct 9, 2014 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
Can you provide the sample input and its expected output.
The closest number should the greater than or lesser than the given number?
Commenting on behalf of Shanmuga Priya Ramalingam:
1.declare 2 array get all values of 1st array. 2.get the number. Using for loop do b[i] = a[i] - number; fine smallest value in b array. Display using b index display closest value in a array.
Yeah you are right, but my question is assume if you have the following input as an array[] = {1, 2, 3, 5, 6, 8}
and the numbe is  "7"  so here 2 numbers are there in the array which is closest to 7 i.e 6 and 8.
So which one should i select.

Similar Questions
0 votes

Given an array of sorted integers and find the closest value to the given number. Array may contain duplicate values and negative numbers.

Example : Array : 2,5,6,7,8,8,9
Target number : 5
Output : 5

Target number : 11
Output : 9

Target Number : 4
Output : 5

+1 vote

Given an array of integers (possibly some of the elements negative), write a C program to find out the *maximum product* possible by adding 'n' consecutive integers in the array, n <= ARRAY_SIZE.

Also give where in the array this sequence of n integers starts.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...