October 31st, 2013, 06:19 AM

Array Problem for C Programming ? Please Help
Hi i can try solve this problem for 2 days
My problem is :
numbers[10]={25,27,17,19,47,3,98,5,124,10};
You write a program at do below processes for above array.
You want a number 1 between 10 at user.
if user enter N value,program write to screen lowest N. number at array.For example user enter 2,program write to screen lowest secondary number of 5 value at array or user enter 10 value,program write to screen maximum number of 124 value at array.
But write the program with don't use sorting algorithm.
Thanks For Help
:D
October 31st, 2013, 02:23 PM

I'd first try a program written from this pseudo code. Then when it failed I would discover and correct the error. The method "show smallest remaining number until enough of them are shown" is simple and does not require sorting per se thus meets your requirement. The approach is certainly workable. That is why I would correct implementation errors rather than replace the fundamental algorithm.
Code:
int
numbers[10]={25,27,17,19,47,3,98,5,124,10},
indexes_used[10],
number_of_smallest_required,
number_of_smallest_found = 0,
candidate_index,
candidate_minimum,
i;
//get number_of_smallest_required from user
//while number_of_smallest_required < number_of_smallest_found
//minimum = INT_MAX from limits.h
//loop with i as the successive indexes of numbers
//if ((numbers[i] < minimum) and (not_in(indexes_used, i, number_of_smallest_found)))
//save candidates
//display candidate_minimum
//update number_of_smallest_found
//update indexes_used
Where int (*not_in)(int*,int,int)
is a function that returns 0 iff (if and only if) the second argument is not found among the values in the array indexed on
[0, last_argument)
[code]
Code tags[/code] are essential for python code and Makefiles!
October 31st, 2013, 03:50 PM

Your explanation of the requirement was less than clear, but what I think you want is:
 For an input N output the largest value of the lowest N values from the array.
There are many ways, some better than others.
Create a function:
Code:
int find_lowest_greater_than( int min, int* d, int len ) ;
that finds the smallest number greater than min in the array data of length len.
Call find_lowest_greater_than() iteratively N times starting with min = INT_MIN, and assign the result to min. After N iterations min will contain the largest of the lowest N values from the array.
find_lowest_greater_than() would start with an initial value result = INT_MAX, and for each number in the array is that less than result, and greater than min, you assign it to result.
Make a stab at that and post what you have if you get stuck.
Last edited by clifford; October 31st, 2013 at 03:53 PM.
October 31st, 2013, 05:35 PM

Problem with "find lowest greater than":
Given a data set with duplicate values the request could summon more numbers than there are unique values.
Comments on this post
[code]
Code tags[/code] are essential for python code and Makefiles!
October 31st, 2013, 08:44 PM

One could include a count of occurrences.
3
7 occurs 4 times
9
[code]
Code tags[/code] are essential for python code and Makefiles!