Thread has been deleted
Last comment
c programming help pls
Sweden m4st4m4st3r4wp 
I have this exercise that i have almost no clue how to solve. here is the function: and then we have this array: int arr[] = {1, 5, 3, 4, 3, 2}; and im supposed to figure out what return i get from: arrayFunc (6, arr) we are supposed to do solve this on paper with pen only.
2019-12-11 03:35
Topics are hidden when running Sport mode.
did you learn recursion yet?
2019-12-11 03:40
yes but no. i dont understand it well...
2019-12-11 03:41
basically the function calls itself int arr[] = {1, 5, 3, 4, 3, 2}; first pass, 2 + ... (# of elements = 5 now) second pass 3 + ... (# of elements = 4 now) third pass 4 + ... (# of elements = 3 now) fourth pass - since 3 < 4, it is arr[0], which is 1 2+3+4+1=10
2019-12-11 03:45
i understand it starts with 2+ but how do you get 3+ and 4+?
2019-12-11 03:51
bc imagine its calling the function again, this time with #ofelements variable as the previous value - 1, making the index one less each time, therefore 3, then 4
2019-12-11 03:52
ahh okay now i think i understand. thank so much man, this might save me.
2019-12-11 03:54
np mens))
2019-12-11 03:54
10 i think
2019-12-11 03:41
but can you tell me how you solved it plz???
2019-12-11 03:42
2019-12-11 03:46
its recursion, you see in +arrayFunc(nrofElements-1, array) you call the function again. So at the beginning you say return array[nrOfElements-1] which is 5, so the value 2 then + arrayFunc(nrofElements-1, array) so you do the same but with 5 instead of 6 in the function call with 5 now the same happens, also here call the function again you do this until the value you called the function with is < 4 at this point return array[0] which is 1, and from there on all the values in the methods are returned so all in all its return 2 + 3 + 4 + 1
2019-12-11 03:49
thank you so much dude
2019-12-11 03:54
Luxembourg zrbr 
it will give arr[5] + arr[5] = 2 + 2 = 4
2019-12-11 03:43
Xyp9x | 
Indonesia Wawzloll 
This is correct
2019-12-11 03:46
2019-12-11 03:47
mens dont confuse him
2019-12-11 03:49
2019-12-11 03:41
United States gtmaniacmda 
it looks like it would return 2 + 3 + 4 + 1 so 10
2019-12-11 03:42
can you explain more please? the "2" comes from array[nrOfElements-1] right? but the the second part i dont understand how to calculate.
2019-12-11 03:43
United States gtmaniacmda 
arrayFunc is entered for the first time nrOfElements starts at 6 hit the first if statement, check is nrOfElements is less than 4; it isn't instead, return array[5] (which is 2) and the arrayFunc when the arrayFunc is 'returned' in this way, it is called recursion no return actually occurs yet; instead, the arrayFunc in the return statement is executed so now arrayFunc is executed again with the new parameters (nrOfElements = 5, array[] = array) check if nrOfElements is less than 4; it isn't return array[4] (which is 3) + arrayFunc but now nrOfElements is 4 check nrOfElements again, if statement fails again return array[3] (which is 4) + arrayFunc but now nrOfElements is 3 check the if statement; it enters! return [0] (which is 1) return occurs; enter the previous arrayFunc (back when nrOfElements was 4) add array[0] to array[3] to get 5; function ends, return to previous arrayFunc add array[4] to 5 and get 8; function ends, return to previous arrayFunc add array[5] to 8 to get 10; function ends, return to original caller with the 10 /done
2019-12-11 03:54
thanks man
2019-12-11 03:55
United States gtmaniacmda 
Think of the function in the return statement as a system of equations that has to be solved; you don't know what arrayFunc(nrOfElements - 1, array) is equal to yet, so you call arrayFunc (in this case, another version of itself, which is recursion) to get the answer (or, to keep with the system of equations analogy, to find a new equation to use to help solve the problem). Eventually, you will get to the 'base case,' which here is the' return array[0]' in the if statement; this is a return statement that doesn't call itself (arrayFunc). Then, this arrayFunc returns to the arrayFunc that called it with the answer. Then THIS arrayFunc can answer what it was called to answer, and it returns the value, until eventually all the arrayFunc called have returned the value they were called to answer, and recursion ends.
2019-12-11 04:01
stfu nerd
2019-12-11 03:56
2019-12-11 04:20
im curious about those studying programming. what job in particular will you be in?
2019-12-11 03:42
the program is called civil engineering in interaction design. i just started it. i have no clue what job i will get when im done. they say u can get almost any data/it-job.
2019-12-11 03:44
oBo | 
Korea Moms_touch 
You develope skynet and terminator
2019-12-11 03:55
Lucid Dream
MAD Lions
Bet value
Amount of money to be placed
Odds total ratio
Login or register to add your comment to the discussion.