Does the function have to have that prototype? That is, can you pass an array of integers instead?
If so, think about how some pseudocode might go if you have a collection of numbers over which you can iterate:
1. Declare a variable 'lowest' and set it to the first value in the collection
2. Iterate over the rest (i.e. starting at the second value) of the elements in the collection
- for each, check if it's value is less than 'lowest'
- if it is... <you fill this bit in> :)
3. ...
Even if you can't pass an array of integers to the function, it would probably be cleaner if you stored them locally in an array (i.e. inside the function) and followed the logic given above...
Hope that helps...
P.S. The other way that you could do it is simply to SORT the collection, then return the first element (assuming the collection is sorted in descending order). There are lots of efficient sorting algorithms described all over the web. That would be a good exercise for you I think...
looping over the array can be fine, same with sorting it. If you are allowed to use STL you may want to use it, as the algorithms are pretty fast, but I am not sure your professor/teacher will allow it. If you want to do something crazy, you could use a set. Though that may be a bit advanced. (point being elements added to a set are sorted without you calling a sort function, just need a comparison function)
if (b < a) { a = b; }
if (c < a) { a = c; }
if (d < a) { a = d; }
if (e < a) { a = e; }
return a;
i think this is very fast, (n-1) comparisons and no needless work.
in the end its almost like the solution of moorecm, but since you dont need to call functions this should be faster.
Thanks for the help people. I actually went with the array that jsmith posted since that helped me understand a hint that my professor told me when he checked out my long code.
i suggest to read the scores into an array then find the lowest of them by putting them into an loop
as,
min=a[0];
for(i=0;i<5;i++)
if(a[i]<min)
min=a[i];
you got the answer