# Perl Programming-To Find Armstrong Number

0
2014

If you are looking for a Pearl program to check whether a number is Armstrong or not, here is the right spot. Let us start with the algorithm first.

Algorithm:

1. Start

2. Read the number to n

3. Initialize sum=0 and temp=n

4. While temp not equal to zero, do the following steps:

5. Calculate rem as temp%10. Now calculate the value of sum as “\$sum+(rem*rem*rem)

6. Now omit the last digit of the number by temp/10 and assign the value to temp

7. If the sum is equal to n, then echo n is “Armstrong number” or else echo “Not Armstrong”

8. Stop

## Perl program for armstrong number

print “Enter the number”;

\$n=<>;

\$t=\$n;

\$s=0;

while (\$n > 0)

{

\$r=\$n%10;

\$i=\$r*\$r*\$r;

\$s=\$s+\$i;

\$n=\$n/10;

}

if(\$s == \$t)

{

print “Armstrong Number”;

}

else

{

print “Not Armstrong”;

}

OUTPUT

Enter the number

153

Armstrong Number

SHARE
Previous articleDining Philosophers Problem Using Semaphores
Next articlePHP Programming Basics-String Operations
Jesna is an assistant professor, digital marketing strategist and professional blogger who stumbled upon writing online since 2009. She started her blogging career in 2010, and never looked back. Since then, she has developed an incredible passion for writing about all sorts of tech. Away from blogosphere, she loves to paint and is the founder of fineartblogger.com