GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-May-2008, 08:31
contherun contherun is offline
New Member
 
Join Date: Apr 2008
Posts: 18
contherun is on a distinguished road
Question

How to find the minimum value in this array?


Hi there,

Assume there is an array called arr with the following defintiion:
int arr[5] = {23, 4, 344, 30, 23};

I need to find out the what is the minimum value is. In this case the values are visible, assume the values are not visble.

The only way i know is to do a bubble sort. But I cannot do a bubble sort becuase i need to find out the actual index value of the minmum number.If i do a bubble sort in the ascending order then it is obviouse the minimum value is in the index 0. But That it not it's actual position. In the above array the minimm value is "4" and the position is 1. But if we dont know the minimum value and where it is,

How do we find out what is the minimum value and it's location in the array WITHOUT doing a bubble sort?

cheers
  #2  
Old 02-May-2008, 09:15
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: How to find the minimum value in this array?


CPP / C++ / C Code:
void FindMinimum( int *array, int arraySize, int *minIndex)
{ int i;
  if(arraySize == 0) 
  { *minIndex = -1;
    return;
  }
  *minIndex = 0;
  for(i=1;i<arraySize;++i)
  { if(array[i] < array[*minIndex]) *minIndex = i;
  }
}
  #3  
Old 06-May-2008, 17:15
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 400
Peter_APIIT is on a distinguished road

Re: How to find the minimum value in this array?


You just need to set the first element of array as minimum, then compare one by one.
__________________
Linux is the best OS in the world.
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the problem and can you fix it (php) oggie MySQL / PHP Forum 8 14-Apr-2008 15:08
Getting a line error in register oggie MySQL / PHP Forum 5 13-Apr-2008 16:16
Logic error with recursion to find smallest in an array aijazbaig1 MS Visual C++ / MFC Forum 4 13-Jul-2006 08:32
Need help deleting the last element in the array headphone69 CPP / C++ Forum 2 15-Mar-2006 19:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.