You are on page 1of 1

College of Engineering and Information Technology

INT201 Object Oriented Programming

2nd semester 2022/2023


Lab Sheet#9

Exercise 1
Write a recursive function printLine() that takes a parameter n of type integer and prints n
stars separated by a space on a single line. For example, calling printLine(5) will print the
following line:
* * * * *
Exercise 2
Write a recursive method for the following function which computes x y:

{
1 if y=0
x if y=1
power ( x , y ) = x∗power ( x , y−1 ) if y >1
1
if y <0
power ( x ,− y )

Test your method by reading x, and y and compute xy. Try with 43 and 5-2.

Exercise 3
Write a recursive method that computes the product of two integers mn by adding m repeatedly n times.

You might also like