Due: October 11, 2019 (Note extension)
Points: 100
Please submit the answers to these two questions in a text or PDF file.
Each function takes 2 arguments; call them m and n. m is the starting number; the n is the ending number.
If m < n, then print m, m+1, …, n, each number on a separate line.
If m = n, then just print m.
If m > n, then print m, m-1, …, n, each number on a separate line.
The file hw1_3.c is available on the class web site. It contains three functions with the above interface. Write each loop in the appropriate function. Remember to add comments!
To turn in: The file hw1_3.c with the three loops added. You need not submit a Makefile for this assignment.
Revision: The previous version had you write 3 functions. This version supplies the function framework; now you need only add the loops where indicated.
The relevant characters, and the C escape sequences to be printed when those characters are encountered, are:
character | print as | character | print as |
---|---|---|---|
newline | \n | backslash | \\ |
horizontal tab | \t | vertical tab | \v |
backspace | \b | carriage return | \r |
form feed | \f | bell | \a |
NUL | \0 | anything else | \ooo |
The “anything else” entry means that any non-printing character other than the ones named in the table is to be printed as a sequence of three octal digits preceded by a backslash. When the escape sequence for a newline is printed, the program is to skip to the next line.
Unfortunately, the program as saved in vis.c will not even compile, let alone run. And the programmer thoughtlessly left off all the comments. Hence, your mission: comment the program, and fix it so it works as described above! You are to turn in a corrected source program, with comments describing the changes you made to get it to work.
To turn in: Turn in a corrected, fully commented vis.c. Your comments are to explicitly say what you changed to make the program compile and work correctly. You need not submit a Makefile for this assignment.
The file hw1_ex.c is available on the class web site. Like hw1_3.c, it contains three functions with the above interface. The third parameter, d, is the increment. Write each loop in the appropriate function. Remember to comment them!
To turn in: The file hw1_ex.c with the three loops added. You need not submit a Makefile for this assignment.
Revision: The previous version had you write 3 functions. This version supplies the function framework; now you need only add the loops where indicated.
|
ECS 36A, Programming and Problem Solving Version of September 30, 2019 at 3:23PM
|
You can also obtain a PDF version of this. |