Smallest and Largest N-Digit Perfect Squares

Problem Statement

You’re given an integer n, and you need to find the smallest and largest n-digit numbers that are also perfect squares.

Example 1: Let n = 2

Smallest 2-digit perfect square is 16 and the largest 2-digit perfect square is 81.

Thus, the output is:

Smallest 2-digit perfect square: 16

Largest 2-digit perfect square: 81

Example 2: Let n = 3

Smallest 3-digit perfect square is 100 and the largest 3-digit perfect square is 961.

Thus, the output is:

Smallest 3-digit perfect square: 100

Largest 3-digit perfect square: 961

Approach to Solve the Problem

You can find the smallest n-digit perfect square using the following formula:

And to find the largest n-digit perfect square, use the following formula:

C++ Program to Find the Smallest and Largest N-Digit Perfect Squares

Below is the C++ program to find the smallest and largest n-digit perfect squares:

Output:

Python Program to Find the Smallest and Largest N-Digit Perfect Squares

Below is the Python program to find the smallest and largest n-digit perfect squares:

Output:

JavaScript Program to Find the Smallest and Largest N-Digit Perfect Squares

Below is the JavaScript program to find the smallest and largest n-digit perfect squares:

Output:

Smallest and Largest N-Digit Perfect Cubes

Problem Statement

You’re given an integer n, you need to find the smallest and largest n-digit numbers that are also perfect cubes.

Example 1: Let n = 2

Smallest 2-digit perfect cube is 27 and the largest 2-digit perfect cube is 64.

Thus, the output is:

Smallest 2-digit perfect cube: 27

Largest 2-digit perfect cube: 64

Example 2: Let n = 3

Smallest 3-digit perfect cube is 120 and the largest 3-digit perfect cube is 729.

Thus, the output is:

Smallest 3-digit perfect cube: 125

Largest 3-digit perfect cube: 729

Approach to Solve the Problem

You can find the smallest n-digit perfect cube using the following formula:

And to find the largest n-digit perfect cube, use the following formula:

C++ Program to Find the Smallest and Largest N-Digit Perfect Cubes

Below is the C++ program to find the smallest and largest n-digit perfect cubes:

Output:

Python Program to Find the Smallest and Largest N-Digit Perfect Cubes

Below is the Python program to find the smallest and largest n-digit perfect cubes:

Output:

JavaScript Program to Find the Smallest and Largest N-Digit Perfect Cubes

Below is the JavaScript program to find the smallest and largest n-digit perfect cubes:

Output:

Sharpen Your Brain With Stimulating Math Puzzles

If you’re someone who loves solving math puzzles and riddles, you’re doing your brain a favor! Solving math puzzles and riddles improves memory, increases problem-solving skills, and can also increase IQ. Some great websites, YouTube channels, and apps provide amazing math puzzles and games for free.