CS 1371 Lecture Notes - Lecture 10: Bogosort, Matlab, Empty String

140 views7 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents