Assignment 2 Sec 11
Assignment 2 Sec 11
(a)It first asks the user for a single integer (say N) upto which
number the user wants. Using the above formula, and first two
numbers as 0 and 1; calculate the next numbers. First print N
numbers in the sequence. [10 points]
(b) Assume the Nth number is 𝑚. For each number above (say 𝑝),
print 𝑝 number of “*”s; surrounded by (approximately)
(𝑚 − 𝑝)/2. 0 number of “-”s both in left and right. The
number of “-”s in the left and right should differ at most by 1.
Total number spaces and “*”’s should sum to 𝑚. Final printed
pattern would resemble a tree. [25 points]
For example, suppose N=6. The Nth number is 13,
(i) first number is 1, print 6 “-”s, 1 *, then 6 “-”s.
(ii) second number is 2, print 5 “-”s, 2 *, then 6 “-”s.
(iii) third number is 3, print 5 “-”s, 3 *, then 5 “-”s.
(iv) fourth number is 5, print 4 “-”s, 5 *s, then 4 “-”s;
(v) fifth number is 8, print 2 “-”s, 8 *s, then 1 “-”s;
(vi) Last is 13. So, print 13 *s.
(c)Write a program that can take as input any recurrence formula,
where the next number calculation depends on M (up to 3)
previous numbers and a constant.
𝑥𝑛 = 𝑐1 * 𝑥𝑛−1 + 𝑐2 * 𝑥𝑛−2 + 𝑐3 * 𝑥𝑛−3 + 𝑐0
First ask the user to input how many previous numbers are
required. Say M is input. M should be between 1 to 3. Then,
using that, ask the user to input for M + 1 coefficients and first
M numbers of the series. [15 points]
(d) Print the new formula from user input. While printing
(i) ensure that you do not print the variables for which the
coefficient is zero,
(ii) ensure that the relation is well-formatted. There should
not be any dangling “+” in the beginning or the end.
[30 points]
(e)Ask the user of a single integer up to which you should print
the series (say N). Starting from M+1-th number, calculate
each new number and print the series up to N+M-th number.
You need to print the index and the number.
[20 points]
Enter Value of N? 8
The numbers are: 1, 2, 3, 5, 8, 13, 21, 34
----------------*-----------------
----------------**----------------
---------------***----------------
--------------*****---------------
-------------********-------------
----------*************-----------
------*********************-------
**********************************
Enter any recurrence formula.
Enter how many previous values are considered (upto 3)?
2
Enter coefficient and Enter value of x_0.
Constant Coef: 1