cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
How do I modify array elements while in
How do I modify array elements while in the for loop?
May 7, 2016 at 2:03am UTC
mistersunnyd
(28)
I have a for loop that traverses an array and finds the max and then sets that element to zero, but that does not work since the for loop is going through the array. Is there a way to solve this?
May 7, 2016 at 2:12am UTC
Arslan7041
(753)
Each time you find a new max, save its index. By the time you get out of the loop, you will have the index of the maximum element saved.
Outside the loop, simply assign 0 to the element at that index.
May 7, 2016 at 2:41am UTC
mistersunnyd
(28)
But if I exit the loop in order to assign 0, then how do I go back into the loop?
Last edited on
May 7, 2016 at 2:42am UTC
Topic archived. No new replies allowed.