Due: April 24, 2023
Points: 100
Call your program “hello.c”.
Each function has 2 arguments; call the first m and the second n. m is the starting number; 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 loopy.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!
Call your program “loopy.c”
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 show.c will not even compile, let alone run. And the programmer thoughtlessly left off all the comments. Hence, your mission: fix the program 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.
Call your fixed program “show.c”.
|
ECS 36A, Programming & Problem Solving Version of April 12, 2023 at 10:07AM
|
You can also obtain a PDF version of this. |