Number Problem Pseudocode
Number Problem Pseudocode
1. Ask for two numbers from the user. Check if second is a factor of the first. Display appropriate
output. Use validation to make sure that the second number is not greater than the first
number.
INPUT first_number
INPUT second_number
// Step 2: Validate that the second number is not greater than the first
PRINT "The second number cannot be greater than the first number. Please try again."
EXIT
ELSE
END IF
2. Write a program to input a number and count the number of digits. The program further checks
whether the number contains odd number of digits or even number of digits.
BEGIN
INPUT p
INPUT q
IF p >= q THEN
EXIT
FOR number = p TO q DO
END IF
END FOR
END
4. A number is said to be Duck if the digit zero is (0) present in it. Write a pseudocode to accept
a number and check whether the number is Duck or not. The program displays the message
accordingly. (The number must not begin with zero)
BEGIN
// Step 1: Ask the user for a number
PRINT "Enter a number:"
INPUT number
// Step 2: Validate that the number does not begin with zero
IF number STARTS WITH "0" THEN
PRINT "Error: The number should not begin with zero."
EXIT
5. A Dudeney number is a positive integer that is a perfect cube such that the sum of its digits is equal
to the cube root of the number. Write a program to input a number and check and print whether it
is a Dudeney number or not.
Example:
Consider the number 512.
Sum of digits = 5 + 1 + 2 = 8
Cube root of 512 = 8
As Sum of digits = Cube root of Number hence 512 is a Dudeney number.
BEGIN
// Step 1: Ask the user for a number
PRINT "Enter a number:"
INPUT number
// Step 4: Check if the sum of digits is equal to the cube root of the number
IF sum_of_digits = cube_root THEN
PRINT "The number is a Dudeney number."
ELSE
PRINT "The number is NOT a Dudeney number."
END IF
END
6. Write a pseudocode for an ATM Machine. Following are the rules laid out by the bank:
a. PIN should be a 4 digit number positive number (first digit non 0)
b. PIN cannot be a palindrome.
Your pseudocode should validate the input and display appropriate output.
INPUT CENTS
// input 36
+ +
| Start |
+ +
|
v
+ +
| Input CENTS |
+ +
|
v
+ +
| CENTS > 99 ? |
+ +
/ \
yes no
/ \
v v
+ + + +
| Output "Enter a valid number of | | QUARTERS ← CENTS DIV 25 |
| cents:" | +------------------------------+
+ + |
| v
| + +
| | REMAINING ← CENTS MOD 25 |
| + +
| |
+ v
| + +
| | Output "Quarters: ", QUARTERS |
| +------------------------------+
| |
v v
+ + + +
| Input CENTS | | DIMES ← REMAINING DIV 10 |
+ + + +
| |
v v
+ + + +
| REMAINING ← REMAINING MOD 10 | + Output "Dimes: ", DIMES |
+ + + +
| |
v v
+ + + +
| NICKELS ← REMAINING DIV 5 | | REMAINING ← REMAINING MOD 5 |
+ + + +
| |
v v
+ + + +
| Output "Nickels: ", NICKELS | | PENNIES ← REMAINING DIV 1 |
+ + + +
| |
v v
+ + + +
| REMAINING ← REMAINING MOD 1 | + Output "Pennies: ", PENNIES |
+ + + +
|
v
+ +
| End |
+ +