Professional Documents
Culture Documents
Task1:: PF Assignment 01 (Functions)
Task1:: PF Assignment 01 (Functions)
Instructions: Implement the following functions in first three tasks and then use these functions to develop the
program in task 4. For each function, think carefully about their return type, formal parameters and their type, and
whether they will be passed by value or by reference. Screen given below shows a sample output. You cannot use arrays
to solve this question.
Task1:
countDigits() is a function which takes an integer n as parameter and count the digits of n. For example, if n=456,
the function will return 3.
Task2:
threeDigitSeparator() is a function which takes a 3-digit non-negative integer n as parameter and separates
each digit of n and return those digits. For example, for n=456, the function will return first digit as 4, second digit as 5,
and third digit as 6. Moreover, threeDigitSeparator() will use countDigits() to checks the number of
digits n has. It returns true if n is 3-digit non-negative integer and false otherwise.
Task3:
threeDigitJoiner() which takes 3 one digit integers as parameter and joins first, second, and third digit in a
manner that the final result is reverse of parameter sequence and returns this joined value. For example, if first digit is
4, second digit is 5, and third digit is 6, then the result will be 654.
Task 4:
Write a program which asks users to enter a 3-digit non-negative integer n and print the reverses digits of n. For
example, if n=456, the program will print “Reverse of 456 is 654.”.
reverseNumber() is a function which takes a 3-digit non-negative integer n as parameter and reverses the digits of
n. To reverse n, the function uses another function threeDigitSeparator() which separates each digit of n and
return those digits. Once threeDigitSeparator() has separated all digits, reverseNumber() calls another
function threeDigitJoiner() which joins first, second, and third digit in a manner that the final result is reverse
of n and returns this joined value.