You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects.
Write a function (running-sum L) that takes a list of numbers L and generates a list of the runnining sums. See the following examples for clarification.
(running-sum '(1 2 3)) ---> (1 3 6) (running-sum '()) ---> () (running-sum '(3 0 -2 3)) ---> (3 3 1 4)
Okay, as the name suggests the running sum or the cumulative sum is the sum of all the numbers that has came so far,
Now for the scheme of the function
Def runningsum (list1):
Rs= 0, list2=list() # these are needed to hold results
For x in list1:
Rs=Rs+ int(x)
list2.append(Rs)
Return (list2)
Here we are having a temp variable, with initial zero and after every items of list1 comes we add that that to the temp, getting next item of the running sum list and append it to the list2 and once all elements are over in list 1 we get out of the loop and then send the list2 which we have saved all the sums in as a return value
Get Answers For Free
Most questions answered within 1 hours.