CSCI 1120 (Low-Level Computing), Spring 2018:
Homework 3
- Credit:
- 10 points.
Be sure you have read, or at least skimmed,
the assigned readings for classes through 1/24.
Please include with each part of the assignment the Honor Code pledge or
just the word ``pledged'', plus one or more of the following about
collaboration and help (as many as apply).1Text in italics is explanatory or something for you to
fill in.
For written assignments, it should go right after your name and
the assignment number; for programming assignments, it should go
in comments at the start of your program(s).
- This assignment is entirely my own work.
(Here, ``entirely my own work'' means that it's
your own work except for anything you got from the
assignment itself -- some programming assignments
include ``starter code'', for example -- or
from the course Web site.
In particular, for programming assignments you can
copy freely from anything on the ``sample programs page''.)
- I worked with names of other students on this
assignment.
- I got help with this assignment from
source of help -- ACM
tutoring, another student in the course, the instructor, etc.
(Here, ``help'' means significant help,
beyond a little assistance with tools or compiler errors.)
- I got help from outside source --
a book other than the textbook (give title and author),
a Web site (give its URL), etc..
(Here too, you only need to mention significant help --
you don't need to tell me that you
looked up an error message on the Web, but if you found
an algorithm or a code sketch, tell me about that.)
- I provided help to names of students on this
assignment.
(And here too, you only need to tell me about
significant help.)
Do the following programming problems.
You will end up with at
least one code file per problem.
Submit your program source (and any other needed files)
by sending mail to
bmassing@cs.trinity.edu with each file as an attachment.
Please use a subject line that mentions the course and
the assignment (e.g.,
``csci 1120 hw 3'' or
``LL hw 3'').
You can develop your programs on any system that provides the
needed functionality, but I will test them on one of the department's
Linux machines, so you should probably make sure they work
in that environment before turning them in.
Note about error checking:
Starting with this assignment, I do want you to do at least minimal
checking that input from standard input is sensible.
As mentioned in class, doing a really great job of parsing and
validating input is not especially easy,
but for our purposes it's enough to check that scanf was
able to get value(s) of the requested type(s) and that the values
meet whatever other criteria the problem states (e.g., not negative
for the second problem).
- (5 points)
Write a C program that asks the user for three integers and prints them
in order from smallest to largest, or an error message if what was
entered is something other than three integers.
(You may recognize this problem as a special case of one
you probably spent some time on in CS1.
Don't try to solve that problem in general for this assignment;
just solve the ``three numbers'' problem
using what we've discussed in class so far -- in particular
I'd rather you not use arrays.)
Clarification:
Note that the numbers do not have to be distinct -- for example,
the user could enter three 0s.
- (5 points)
Write a C program that asks the user for two non-negative integers,
call them and , not both zero, and computes and prints
, the greatest common divisor of
and , using a recursive version of Euclid's algorithm.
Print an error message if what was entered is not two integers,
or either input is negative, or both are zero.
(Note that you will not get full credit unless you use recursion.)
Euclid's algorithm can be described recursively thus:
For non-negative integers and ,
not both zero, with ,
where
is the remainder when is divided by .
Footnotes
- ... apply).1
-
Credit where credit is due:
I based the wording of this list on a posting to a SIGCSE mailing
list. SIGCSE is the ACM's Special Interest Group on CS Education.
Berna Massingill
2018-02-13