You are on page 1of 1

Tutorial sheet 1

1. Write an algorithm that reads a number 𝑛 and returns the first 𝑛 numbers. n should be a
whole number greater than 0.
2. Write an algorithm that reads a number 𝑛 and returns the sum of the first 𝑛 numbers.
3. Write an algorithm to calculate the area of a circle.
4. Write an algorithm to solve a linear equation
5. Write an algorithm that reads a person’s name and sex, and returns the message “good
morning Mr. name” if the person is a man and “Good morning Mrs. Name” for a woman.
6. Write an algorithm that calculates the density of an object. The algorithm should get the
length, width, height in meters and mass in kg of the object from the user.
7. Write an algorithm that calculates the speed of an object given the distance covered and time
taken
8. Write an algorithm that askes the user to enter random numbers. The algorithm stops when
the user enters a value zero.
9. Write an algorithm that prompts the user to select a number between 1 and 7 inclusive and
displays the day of the week corresponding to the number.
10. Write and algorithm that swaps the content of two variables A and B. that is the content of
the variable A is stored in B and that of B is stored in A.
11. Write an algorithm that will calculate the %gain or %loss of an item given the cost price
and the selling price.

SWE114 Introduction to Algorithms (Mr. Ndayo Fonteng R) 1

You might also like