CSCI 1120 (Low-Level Computing), Fall 2021:
Homework 3
- Credit:
- 10 points.
Be sure you have read, or at least skimmed,
the assigned readings for classes through 9/08.
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)
one of two ways:
- using my mail-files script, linked from the course Web site
under “Links”.
- by putting them in your course “TurnIn” folder on
Google Drive.
(Note that I want plain-text files, ideally with an extension of .c,
but if Google Drive balks at that, rename to have an extension of .txt.
I want something I can compile as is, except for possibly a change of filename.
So no screenshots!)
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 want you to do at least minimal
checking that input from standard input is sensible.
Doing a really great job of parsing and
validating input is not especially easy,
but for our purposes I say 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 has been presented in video lectures so far --
in particular I'd rather you not use arrays.)
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 .
Include with your assignment the following information.
For programming assignments, please put it a separate file.
(I strongly prefer plain text, but if you insist you can put
it in a PDF -- just no word-processor documents or
Google Drive links please.)
For written assignments, please put it in your main document.
This should include the Honor Code pledge, or just the word “pledged”,
plus at least one of the following about
collaboration and help (as many as apply).
Text in italics is explanatory or something for you to
fill in;
you don't need to repeat it!
- I did not get outside help aside from course
materials, including starter code,
readings, sample programs, the instructor.
- 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, 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.)
This should be a brief essay
(a sentence or two is fine, though you can write as much as you like)
telling me what if anything you think
you learned from the assignment,
and what if anything you found
interesting, difficult, or otherwise noteworthy.
2021-09-28