CS 1371 Lecture Notes - Lecture 10: Bogosort, Matlab, Empty String
Document Summary
Outputs (1): (double) a number representing the sum of the input"s digits. Given a positive integer, write code that will recursively sum its digits. Hint: use mod to isolate the value in the ones position of the number and use division with floor rounding to remove the that digit from the integer. Test cases: x = 9; sum1 = adddigits(x); sum1 == 9 y = 45; sum2 = adddigits(y); sum2 == 9. You have just completed your implementation of bogosort, but you want to check whether it is working correctly. Write code that will determine whether the vector is correctly sorted in ascending order. You must use recursion, and you cannot use the sort function. Hint: think about what a sorted list requires in terms of adjacent numbers. Test case: vec = [6 2 7 8 9]; logical = issorted(vec) logical ==> false.