Sunday, June 30, 2013

C++(beginner) basic algorithms with arrays. Findings the smallest/biggest element in array.

Suppose we have array .
int a[1000];
we read n elements and need to find the minimum from them.
we have int min; In "min" variable we need to find the smallest element.
first we suppose that the smallest element is the first one, so we give our "min" variable the first element's value. min=a[1];
now we loop over the other elements and check if the coming element is less than the value we had in "min" then we update the value of min.

Here is the full code


LEAVE YOUR QUESTIONS IN COMMENTS

No comments:

Post a Comment