You are on page 1of 3

Priyankar Paul 1

29SCS124

Ex. No: 6a
02/02/2011 Armstrong Series

Aim:
To print the Armstrong series.

Algorithm:
1. Start
2. Enter the limit as n.
3. Initialize
a. For I = 1 to n
b. {
c. a=i
d. b=i
e. c=i
f. sum=0
g. d=0
4. while b is greater than 0 perform
a. s = int of (b%10)
b. d = d+1
c. b = int of (b/10)
5. while a is greater than o perform
a. r = int of (a%10)
b. sum = sum + (r raised to d)
c. a = int of (a/10)
6. if sum is equal to c then print sum thus printing the armstrong series
7. Stop
Priyankar Paul 2
29SCS124

Program:

print "Enter the max:";


$n=<stdin>;
print"The Armstrong Series is: \n";
for($i=1;$i<=$n;$i++)
{
$a=$i;
$b=$i;
$c=$i;
$sum=0;
$d=0;
while($b>0)
{
$s=int($b%10);
$d=$d+1;
$b=int($b/10);
}
while($a>0)
{
$r=int($a%10);
$sum=$sum+($r**$d);
$a=int($a/10);
}
if($sum==$c)
{
print "$sum\n";
}
}
Priyankar Paul 3
29SCS124

Output:

Enter the max:999999


The Armstrong Series is:
1
2
3
4
5
6
7
8
9
153
370
371
407
1634
8208
9474
54748
92727
93084
548834

Result:

Thus the PERL program to print the Armstrong series was successfully executed and its
output was verified.

You might also like