armstrong code example
Example 1: armstrong
public class Armstrong {
public static void main(String[] args) {
int number = 1634, originalNumber, remainder, result = 0, n = 0;
originalNumber = number;
for (;originalNumber != 0; originalNumber /= 10, ++n);
originalNumber = number;
for (;originalNumber != 0; originalNumber /= 10)
{
remainder = originalNumber % 10;
result += Math.pow(remainder, n);
}
if(result == number)
System.out.println(number + " is an Armstrong number.");
else
System.out.println(number + " is not an Armstrong number.");
}
}
Example 2: armstrong
#include <stdio.h>
#include <math.h>
void main()
{
int i, num, result=0, remainder;
printf("Enter 3 digit number: ");
scanf("%d",&num);
for( i=num ; i != 0 ; i/=10)
{
remainder = i % 10;
result += remainder * remainder * remainder;
}
( (result == num) ? printf("%d is an Armstrong no.",num) : printf("%d isn't an Armstrong no.",num) );
}