You are on page 1of 2

INDIAN INSTITUTE OF SPACE SCIENCE AND TECHNOLOGY

THIRUVANANTHAPURAM 695 547

First Year B. Tech. - Assignment Sheet


MA122-Computer Programming and Applications

23.02.2019 Maximum Marks: 10 Assignment Sheet 6

————————————————————————————————————————

a. The Towers of Hanoi problem consists of three rods and n disks of different sizes. The
object is to move the disks that are stacked, in decreasing order of their size, on one
of the three rods to a new rod using the third one as a temporary rod. The problem
should be solved according to the following rules:
1 When a disk is moved, it must be placed on one of the three rods
2 Only one disk may be moved at a time, and it must be the top disk on one of the
rods.
3 a larger disk may never be placed on top of a smaller disk.

Write a recursive function Tower-Hanoi to implement this. Find the total number of
moves required.

b. Write a program to find the determinant of a square matrix. Let A be a square matrix
of order n ≤ 10. Write A = (ai,j ), where ai,j is the entry on the row number i and
the column number j, for i = 1, · · · , n and j = 1, · · · , n. For any i and j, the number
Mi,j (called the minor) to be the determinant of the square matrix of order (n-1)
obtained from A by removing the row number i and the column number j. Then, the
determinant (det) of the matrix A can be found from the following formula:
X
n
det(A) = (−1)i+j ai,j Mi,j (1)
j=1

for any fixed i. In your program use i = 1.


c. Write a function that rotates 90o clockwise a two-dimensional square array (of any
size) of ints. For example, it would transform the array
11 22 33
44 55 66
77 88 99
into the array

1
77 44 11
88 55 22
99 66 33

Program submission:

Name the programs as XXXA6Y.cpp, where XXX is the last three digits of your student
id and Y is program number. For example, if the student id is ‘sc19b150’ and your
program number is ‘a’ then the file name should be 150A6a.cpp. Submit the program
using ftp to the server: 172.20.2.200

You might also like