Revision 1, April 30, 2025: A typographical error in the output of the program in problem 2 was corrected. The statement in the problem (above the sample run) is correct.
Due: April 30, 2025
Points: 100
> 2 4 2,4 is not a valid square; the numbers must be between 1 and 3 inclusive > 2,4 Illegal character in input "," >The upper left square has co-ordinates (1, 1) and the lower right corner has coordinates (3,3). If there are no errors, your program’s exit status code is to be 0; if there is an error, your program’s exit status code is to be 1.
Here is an example input and output:
> 1 1
# #
X X # #
X X # #
X # #
X X # #
X X # #
# #
#######################
# #
# #
# #
# #
# #
# #
# #
#######################
# #
# #
# #
# #
# #
# #
# #
Call your program “tac.c”.
For a given number n, let k be the least number of iterations needed to reach the number 1 (excluding the initial value). Then k is called the total stopping time of n. For example, if n = 29, then the sequence is:
Write a program that takes as input a positive integer and prints both the sequence and the total stopping time for that integer. Prompt the user with “> ” (note the trailing space and no newline). The output should look like (user input is in red):
> 29 29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 The total stopping time for 29 is 18If the input is not an integer, print the following error message on the standard error:
input: not a valid integer.replacing input with the input. If the input is an integer but is not positive, print the following error message on the standard output:
input: input must be a positive integer.replacing input with the input.
Call your program “collatz.c”.
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 |
Call your fixed program “show.c”.