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 29-Apr-2008, 17:12
contherun contherun is offline
New Member
 
Join Date: Apr 2008
Posts: 18
contherun is on a distinguished road
Arrow

without doing bubble sort how to find the minimum number?


Hi there

assume there an "int" array called numbers:

int numbers[5] = {23, 45, 3, 22, 12};

In this case since we can see the array elements it's obviouse that which is the lowest. But assume we dont see those elements. Then Without doing a bubble sort how do i find the lowest in those elements?

PS: I need to do this WITHOUT using pointers.
  #2  
Old 30-Apr-2008, 02:38
baccardi baccardi is offline
Junior Member
 
Join Date: Mar 2006
Posts: 44
baccardi is on a distinguished road

Re: without doing bubble sort how to find the minimum number?


#include <limits.h>

int min;
int i;

min = INT_MAX;
for (i = 0; i < 5; i++)
if (numbers[i] < min)
min = numbers[i];
  #3  
Old 30-Apr-2008, 04:54
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 103
L7Sqr will become famous soon enough

Re: without doing bubble sort how to find the minimum number?


Quote:
Originally Posted by contherun
I need to do this WITHOUT using pointers
Realize that this is going to be problematic. You are using an array. When you index an array in the following way
CPP / C++ / C Code:
array[i]
it is actually syntactic sugar for the following
CPP / C++ / C Code:
*(array + i)
which is pointer dereferencing.
Unfortunately, baccardi gave you a direct answer so you could not learn from this assignment. Although I would change parts of that example it will probably do what you need.
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

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
How to sort in C++ alphabetically wilen CPP / C++ Forum 5 20-Apr-2007 14:43
Converting a number amount to text Godzilla CPP / C++ Forum 5 31-Mar-2006 11:38
Anyone can write a program code for this??? chriskan76 C Programming Language 1 19-Oct-2004 20:25
Apache2 config issues monev Apache Web Server Forum 2 28-Jun-2004 06:19

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

All times are GMT -6. The time now is 23:27.


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