RM Coding Task-Phase Worksheet
Date issued: 07/11/2022
Date due: 14/11/2022
1. Write a C++ program to sort a character array alphabetically using
bubble sort. (lower case only). Eg: input: “worksheet” Output:
“eehkorstw”
2. Write a C++ program to multiply two matrices and print the product.
If the entered matrices are not compatible then print a message
saying so.
3. In a given matrix for all zero elements the corresponding row and
column must be replaced with zeroes. Write a C++ program to do
that.
Eg: Input: [ 1 2 0 Output: [ 0 0 0
234 230
333] 330]
4. Write a C++ program to print whether a number is a hill number or
not.
Note: Assume that a Hill Number is a natural number that has digits in
ascending order followed by digits in descending order where
consecutive digits are not the same i.e. the number has a peak and an
ascending slope and descending slope.
Example:
Hill Number: 147521, 23454
Not Hill Number: 1, 12, 22, 12334, 123212321
5. Write a C++ program to input a decimal number and print its
equivalent hexadecimal, octal and binary forms.
(If you are unaware of different number systems then please learn about them).6.
Write a C++ program to find if two numbers are Amicable numbers.
Note: Amicable numbers are two different numbers such that the sum of proper divisors of each
is equal to the other number. e.g. 220 and 284
Factors of 220 1 + 2+ 4+ 5+ 10+ 11+20 +22+44+55+110 = 284
Factors of 284 1 + 2+ 4+ 71+142 = 220
6. Write a function for Bubble and Selection Sort. Ask the user for
which method to use: ‘s’ for Selection Sort and ‘b’ for Bubble Sort.
Call the correct function based on the user’s choice. After sorting
the array, call another function that implements Binary Search to
find the position of the number taken as input from the user. [Take
the array as input from the user].
7. Write a function to copy a string into another string using pointers.
8. Write two functions:
[Link] perform matrix multiplication [Link]
find the transpose of a matrix.
Use two matrices to verify the identity (A.B)’ = B’. A’
9. (a) Given a 2D character array, where each row is a string, write a
function which rearranges the strings in ascending order based on
their lengths.
Input: word
number
cat
Output: cat
word
number
(b) Also, sort each individual string in ascending order.
Output: act dorw
bemnru
10. Display the first 40 terms of the Fibonacci sequence using recursion.
It should not take more than 1 second to execute the program.
11. Implement Binary Search using recursion. (Take array as input).
12. Find the factorial of a number using recursion.
13. Find sum of digits of a number with and without recursion.
14. Implement the Euclidean algorithm to find the greatest common
divisor of two numbers.
15. Implement a sort of your choice (bubble/selection) using recursion.
(Take array as input).
16. Input any graph, create its adjacency matrix and perform Dijkstra's,
Kruskal's, and Prim's Algorithm.