Armstrong number program in Ruby




What is Armstrong Number??

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.

For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. 

Armstrong Number Program in Ruby

         #!/usr/bin/ruby
            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

Popular posts from this blog

how to customize dashboard in active admin gem in rails 4

fibonacci series in Ruby

Write a program to Sum of Digits in JQuery?