Check whether a number is Armstrong

This program takes an input from the user in the console window and checks if the entered number is an armstrong number. A number is said to be an Armstrong number if and only if the sum of the cubes of each individual digit in that number equals to that number.This program is done in python.
 
def arm(x):
    m=x;
    s=0;
    while (m>0):
        r=m%10;
        s=s+r*r*r;
        m=m/10;
    if(s==x):
        print x
        print " Is An Armstrong Number";
    else:
        print x
        print " Is Not An Armstrong Number";

x=input(); arm(x);

Description:
The arm(x) performs operations on the user input x, then it displays the output according to the result achived. r is a variable which stores the last digit of x and s is a variable which stores the sum of the cubes of the digits. Then after the termanating condition, the while loop stops and a condition is used to check whether the variable s is equal to the input.

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Hackerrank Modified Kaprekar Numbers Solution

Bit Stuffing Code Implementation in Java