Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Finding Smallest int in an int array

Posted on 2003-03-01
Medium Priority
198 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
• 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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more adâ€¦
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a Gâ€¦
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relatâ€¦
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
###### Suggested Courses
Course of the Month13 days, 7 hours left to enroll