Solved

# Finding Smallest int in an int array

Posted on 2003-03-01
Medium Priority
197 Views
how can i iterate through an int array of 256 int's and find the smallest number and save it to a var.?

I know it sounds simple (and probably is) but i cant get it, my teacher says its less than 10 lines of code
0
Question by:gregrego
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 3
• 2
• +1

LVL 3

Expert Comment

ID: 8050844
i am not in the habit of doing homework for those who don't even try...
post some code

-loki
0

Author Comment

ID: 8050864
well, its a multifile program and its hard because this is the only function in this cpp.

And yes i have been trying for hours, if you dont know how to then dont post, you didnt have to be an ass.
0

Author Comment

ID: 8050889
k nm i got it i was just missing an if statement!! FUCKKK

int Short(int const * const piArray)
{
int iShort = piArray[0];
for(int iCount,iCount<256,iCount++)
{
if(piArray[iCount])
{
if(piArray[iCount] < iShort)
iShort = piArray[iCount];
}}}
return iShort;
}

0

LVL 6

Accepted Solution

PlanetCpp earned 200 total points
ID: 8051023
lol hey i'll take em
0

LVL 6

Expert Comment

ID: 8051024
i feel bad lol you can ask the moderators to delete the post and reimburse the points
0

Expert Comment

ID: 8051026
{
int smallest;

smallest = Array[0];
for(int i = 0; i < 256; i++)
{
if(Array[i] < smallest)
smallest = Array[i];
}
return smallest;
}

int FreePoints = mine;  :-)
0

Expert Comment

ID: 8051029
{
int smallest;

smallest = Array[0];
for(int i = 0; i < 256; i++)
{
if(Array[i] < smallest)
smallest = Array[i];
}
return smallest;
}

int FreePoints = mine;  :-)
0

Expert Comment

ID: 8051033
oops lol
0

Author Comment

ID: 8051945
lol thats ok its only 50 i got so many points left lol
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. Aâ€¦
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a â€¦
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor anâ€¦
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
###### Suggested Courses
Course of the Month15 days, 14 hours left to enroll