Explain why for loops and arrays work so well together. What tasks can for loops complete on arrays? Provide a code example of a for loop being used with an array and explain how it works.
For loops go well together because it can make putting inputs into the array easier. If you need to put multiple numbers in an array at once a for loop can be really useful. for example here is the code for that function.
for(int i = 0; i<10; i++)
cin>>array[i];
This reads the users input and puts it in the array.
No comments:
Post a Comment