Skip to main content

TCS

TCS OA-8 2024

Problem Description

Given an integer n, return true if it is an Armstrong number; otherwise, return false.
An Armstrong number is a number that equals the sum of its own digits, each raised to the power of the number of digits.

 Input Format

The first line contains an integer N.

Output Format

Print the true if N is Armstrong otherwise false.

Constraints

  • 1 ≤ N ≤ 10⁴

Example

Sample Input:

153

Sample Output:

true

Explanation:

The number 153 is an Armstrong number because it equals the sum of its own digits each raised to the power of the number of digits. For 153, there are 3 digits, so we calculate 1³+5³+3³, which is 1+125+27=153. Since the sum equals the original number, 153 is an Armstrong number.