I have a function which receives a one-dimensional array and a number from a user and adds these two together.
Sample:
0 1 2 3 4 5 6 7 8
User : 9
9 10 11 12 13 14 ...
I've been using the following code:
for(int i =0; i < arr; i++){
arr[i] = arr[i] + usrNumber;
}
Now this seems terribly inefficient as I have to essentially iterate through every single position of the array and add the values together.
I have read of the block method from a previous post but I was under the impression that it had to be at least two-dimensional for it to work. What is a way to improve this function?