if i am understanding this right t gets read from input and the first for loop says thats how many elements we are going to use in the array and assign them values...please correct me if i am wrong. Then the second for loop loops through each index of the array right? Assuming that I am correct how do I access the value in each index? I have tried many different ideas but I am always wrong. Any help is greatly appreciated :)
Remember though that array indexes start at 0 (i.e an array declared as int arr; contains the three elements arr, arr and arr) so your loops are skipping the first element of the array. Also make sure not to allow input over 10 (well actually 9 in this case because you're starting at 1) so that you don't run over the end of your array!
You're on the right track and you should keep reading up on arrays.
so now that I am looping through the different indexes how do I use the values associated with that particular index at the time? say my first element in the array has 231 and the second element has 42 stored in them...How do I get that value and from the first element manipulate it and continue with the second element 42 and then the third forth fifth and so on? Thanks again for your help
If you can assign those numbers to an index you should already know. arrayName[ index ]
i think it is another for loop i need if i am not mistaken :) thx
Originally Posted by whiteflags
Nope thought I had what i was looking for until i saw that semicolon after my next for loop.....Still unsure on how to process each element of the array, get its number without any other numbers, manipulate it and move on....still trying though :/
Not sure what your confusion is. Perhaps you are trying to access arr the same way it was used in scanf(). If so, then understand that scanf() requires an address to store the input into, so the address-operator (&) was used for each arr element. But you don't use that when you want to access the value stored in the arr element.
Originally Posted by James Charny
What if i didnt want to print each value...only just the first one...do somethings to it but not add a value to the element...continue through the loop until I get to the next value. I feel that if I want to get the number from the current index I need another for loop inside of the empty one I have when I first drew up this post
Originally Posted by Tclausex
Well, then don't print the value. I was just showing 2 examples of accessing the element. You'll have to be more specific about "do something".
You don't need a nested loop. 1 dimensional array needs only 1 for() loop. 2 dimensional array needs 2 for() loops, and so on. Assuming you want to access each sequentially.
Of course, you always use decision branching to skip certain elements, or use some algorithm to calculate an integer value to use as index for non-sequential access.
But no, to access the element of the current index, you simply use the array name + index in an expression and it will be evaluated for the value bound to that element, i.e. arr[i].