I have an array of 20 elements with numbers between 1 and 8. I need a for loop that will give me the number of elements greater than 1???
jjmy95 0 Newbie Poster
Recommended Answers
Jump to PostCreate another variable to store the number of 1's. You go through all elements of the array and each time it equals 1 you increment that variable by 1.
You could think of that by yourself ain't that hard.
Jump to PostI'll give you a hint to what I'd do.
Use a for loop to iterate through the array
Use an if statement to check if the number is greater than 1.
You'll need to include a counter which you will increment every time the if statement is successful.
This is …
All 5 Replies
Jiwe 0 Junior Poster in Training
jjmy95 0 Newbie Poster
jjmy95 0 Newbie Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
Grn Xtrm 84 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.