0% found this document useful (0 votes)
65 views

Task1:: PF Assignment 01 (Functions)

The document describes functions to work with 3-digit integers: 1. countDigits() counts the digits in an integer. 2. threeDigitSeparator() separates the digits of a 3-digit integer and returns them. It uses countDigits() to validate the input integer. 3. threeDigitJoiner() joins 3 digits in reverse order and returns the result. 4. A program is to ask the user for a 3-digit integer n, reverse its digits using the above functions, and print the result.

Uploaded by

saad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Task1:: PF Assignment 01 (Functions)

The document describes functions to work with 3-digit integers: 1. countDigits() counts the digits in an integer. 2. threeDigitSeparator() separates the digits of a 3-digit integer and returns them. It uses countDigits() to validate the input integer. 3. threeDigitJoiner() joins 3 digits in reverse order and returns the result. 4. A program is to ask the user for a 3-digit integer n, reverse its digits using the above functions, and print the result.

Uploaded by

saad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

PF Assignment 01 (Functions)

Deadline: Friday 16 April 2021 till 11:00 p.m.


th

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.

You might also like