Prompt the user for an integer and test if it’s even or odd. Consider using the way Ruby rounds operations on integers when appropriate. Save this program in a file called compare.rb.
Prompts the user for an integer between 5 and 10 (inclusive)
and displays whether or not the input was correct. Implement this
using an if
/else
statement.
Prompts the user for an integer between 5 and 10 and then
informs the user if the integer was below the range, in the range,
or above the range. Implement this using a case
statement.
Write a program that, given two points on a two-dimensional graph, outputs a message (string) if the line that connects them is horizontal or vertical, or if the slope is positive or negative.
Write a program to solve a system of two linear equations. A linear equation is a mathematical equation that describes a line through its slope (m) and its y-intercept (b), and it will take the form y = mx + b. Make sure to account for the cases where there is no solution or where there are an infinite number of solutions.
The unit pulse function, d[n], is very important in digital signal processing. This function is defined for integers only. It is equal to 1 when n is 0, and it is equal to 0 when n is any other integer. Write a program that prompts the user for an integer n, and returns the value d[n].
Prompt the user for integers x,
y, and z. Implement the
decision tree shown in Figure 4-6 based on the values
using if
statements. Output how
many of the variables are greater than 0. Note: each right flow option
represents false, and each left flow option
represents true.
18.117.138.178