Sie sind auf Seite 1von 2

CS 159 – Spring 2009 – HW #02 – 5 Points Possible

Due: Monday February 9th, 2009 at 11:00pm


What will you submit? A single M-file (a file with a .m extension) will be submitted electronically via the
sage server (requires SecureCRT from Windows). If you have a concern regarding how to submit work, please
visit course staff prior to the deadline for this assignment. No late work will be accepted.
Course Programming and Documentation Standards Reminders (page 11 of Spring 2009 course packet):

• Include the head_Mhw at the TOP of your M-file. Your header MUST NOT interfere with the
execution of your program. Complete your header including your Purdue e-mail address, your lab
division and section, and a description of your program (what it does and how it does it).
• Do NOT use the clc command.
• Do NOT use multi-line MATLAB comments %{ and %}. Single line comments expected.
• Comment each variable in your program the first time it is used. Your comment should introduce your
variable (why is this variable needed in the program? what does it do?).
• Indent exactly two spaces (NOT FOUR which is the MATLAB default, see page 75 of the notes packet).
• Use meaningful variable names! Rarely are single character variable names meaningful.
• Your program must accept input and produce output in the same manner as seen in the example
executions in this document.
• Place a space between all operators and operands.
• Do NOT single space the entire program. Use blank lines when appropriate.
Problem Description: Given a range of non-negative integer values (smallest and largest) count and display
those numbers whose consecutive digits have the same difference.
Example: 1234 Example: 4246

Digit 1 Digit 2 Difference Digit 1 Digit 2 Difference


4 3 1 6 4 2
3 2 1 4 2 2
2 1 1 2 4 -2

• This example does meet the criteria in the • This example does NOT meet the criteria in the
problem statement. problem statement.

Example Execution #1: Example Execution #3:


Enter the smallest number: 100 Enter the smallest number: 0
Enter the largest number: 200 Enter the largest number: 10
111 123 135 147 159 0 1 2 3 4 5 6 7 8 9 10
Total Numbers Identified: 5 Total Numbers Identified: 11

Example Execution #2: Example Execution #4:


Enter the smallest number: 1000 Enter the smallest number: 55
Enter the largest number: 2000 Enter the largest number: 60
1111 1234 1357 55 56 57 58 59 60
Total Numbers Identified: 3 Total Numbers Identified: 6

• Any one-digit or two-digit number will meet the


described criteria.
Notes:

• The smallest value will always be non-negative.


• The largest value will always be greater than or equal to the smallest value.
◦ There is no need to validate for either condition.
• There is no need for arrays, vectors, matrices, or tables in this assignment.
• The following built-in MATLAB functions may be used when solving this problem:
◦ input, fprintf
◦ mod, floor, ceil, abs
▪ Other functions must be approve by a course staff member.
◦ if, while, for – are not functions and their use is expected in this problem.
• Hint – See example #4 starting on page 89 of your notes for a problem that uses techniques similar to the
ones you might use to solve this problem.
Academic Integrity Reminders:

• This is an individual assignment. All of the work you submit is expected to be your own. Once you
begin to write your algorithm (either code or flowchart) you should only consult course staff members
for assistance.
• Do not share access to your work (in any form) with another student.
• Be mindful when working side-by-side with others in the course (including during the evening TA
hours), working as such can lead to the development of a collaborative effort with no distinguishable
differences by two different students.
• Please refer to the course packet regarding academic integrity policies and consequences for being found
in violation.
How will be program be tested?

• Each of the example cases shown will be used along with a few other reasonable test cases.

Das könnte Ihnen auch gefallen