Docsity

Solved Practice problems - Computing for Engineers | CS 1371, Exams of Computer Science

Partial preview of the text

Download Solved Practice problems - Computing for Engineers | CS 1371 and more Exams Computer Science in PDF only on Docsity!

In this set of practice problems, many of the problems describe the parameters of the function by name. This is merely to facilitate explanation of the problem. Feel free to use whatever more appropriate name you choose for the actual parameters when writing your solutions. The problems in this part will mimic some basic function built into Matlab, so they should be relatively easy fo solve. Write the function my_iter_sum that take a vector as its only parameter and returns the sum of the values in that vector. Use iteration (looping) to solve the first 4 problems. (Try doing this with both a for loop and while loop for extra practice for the first 4 problems). Using while loop iter _sumivec) ind = 1; while ind ret = ret + ve ind = ind + 1; denyth ives; (ind); end Write the function my_iter_prod that take a vector as its only parameter and returns the product of the values in that vector. Use iteration (looping) to solve this problem l:length (ve vet = ret * end Loap _iter prodt & Using wh. function ret = ret = 1; in 3 ind length (wv xn ret * v ind = ind + 1; end