2. Let x be a real number, and n be an integer. Devise an algorithm that computes x n . [Hint: First, give a procedure for computing x n when n is nonnegative by successive multiplication by x, starting with 1 until we reach n. Then, extend this procedure and use the fact that x –n = 1/x n to compute x n when n is negative.]
The following questions are independent.
1. A palindrome is a string that reads the same forward and backward.
Using our algorithmic language, propose an
n characters is a palindrome.
2. Let x be a real number, and n be an integer.
Devise an algorithm that computes x
n
.
[Hint: First, give a procedure for computing x
n
when n is nonnegative by successive
multiplication by x, starting with 1 until we reach n. Then, extend this procedure and use
the fact that x
–n
= 1/x
n
to compute x
n
when n is negative.]
3. The median of a set of integers is the middle element in the list when these integers are
listed in increasing order. The mean of a set of integers is the sum of integers divided by
the number of integers in the set.
Write an algorithm that produces the maximum, median, mean, and minimum of a set of
three integers.
Answer only 2 question
Trending now
This is a popular solution!
Step by step
Solved in 2 steps