Caitlin-havener Posted March 3, 2011 Share Posted March 3, 2011 I need to write a code with two nested for loops that searches through an entire 100 by 100 array to count up the number of negative numbers it containns. The code prints out the number of negative numbers found, or "no negative numbers were found".I know how to do the nested for loops but not sure how to count up the number of negative numbers.... Link to comment Share on other sites More sharing options...
boen_robot Posted March 3, 2011 Share Posted March 3, 2011 Have a separate variable serving as a counter staring at 0. Check each array member to see if it's less than 0, and if it is, increment the counter by one. After you're done with the loop, you could check the counter to see if it's something other than 0, and print "no negative numbers were found" or the counter itself. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.