Page 1 of 13
Create a function that takes a positive integer and returns the number with its digits reversed. For example, if the input is 123, the output should be 321.
Input:
reverseNumber(123)
Output:
321
The digits 1, 2, 3 are reversed to become 3, 2, 1
Input:
reverseNumber(456789)
Output:
987654
The digits 4, 5, 6, 7, 8, 9 are reversed to become 9, 8, 7, 6, 5, 4
Input:
reverseNumber(1000)
Output:
1
Leading zeros are ignored, so 1000 reversed becomes 1
Create a function that generates and prints the Fibonacci series up to n terms. The Fibonacci series starts with 0, 1 and each subsequent number is the sum of the previous two numbers.
Input:
printFibonacciSeries(5)
Output:
0, 1, 1, 2, 3
First 5 terms: 0, 1, 1, 2, 3 (each number is sum of previous two)
Input:
printFibonacciSeries(8)
Output:
0, 1, 1, 2, 3, 5, 8, 13
First 8 terms: 0, 1, 1, 2, 3, 5, 8, 13
Input:
printFibonacciSeries(3)
Output:
0, 1, 1
First 3 terms: 0, 1, 1
Create a function that determines if a given number is prime. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Input:
isPrime(7)
Output:
true
7 is prime because it has no divisors other than 1 and 7
Input:
isPrime(24)
Output:
false
24 is not prime because it has divisors: 2, 3, 4, 6, 8, 12
Input:
isPrime(1)
Output:
false
1 is not considered prime by definition
Create a function that swaps the values of two variables without using a temporary variable. This is a common programming puzzle that tests your understanding of arithmetic operations.
Input:
swapNumbers(3, 6)
Output:
[6, 3]
3 and 6 are swapped to become 6 and 3
Input:
swapNumbers(10, 20)
Output:
[20, 10]
10 and 20 are swapped to become 20 and 10
Input:
swapNumbers(0, 5)
Output:
[5, 0]
0 and 5 are swapped to become 5 and 0
Create a function that calculates the factorial of a given number. The factorial of a number n (denoted as n!) is the product of all positive integers less than or equal to n.
Input:
factorial(5)
Output:
120
5! = 5 × 4 × 3 × 2 × 1 = 120
Input:
factorial(3)
Output:
6
3! = 3 × 2 × 1 = 6
Input:
factorial(0)
Output:
1
0! is defined as 1 by convention
Page 1 of 13