Armstrong number program in Ruby
For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
class Armstrong
puts "Enter a number"
number=STDIN.gets.to_i
sum=0
d=number
while (d!=0)
sum=sum+(d%10)*(d%10)*(d%10)
d=d/10
end
if(sum==number)
puts "your number is Armstrong"
else
puts "Not Armstrong"
end
end
Comments
Post a Comment