Write of length program and to check whether the number is
Armstrong or not.
Answers
Answer:
positive integer is called an Armstrong number of order n if
abcd... = an + bn + cn + dn + ...
In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example:
153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.
Example 1: Check Armstrong Number for 3 digit number
public class Armstrong {
public static void main(String[] args) {
int number = 371, originalNumber, remainder, result = 0;
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber % 10;
result += Math.pow(remainder, 3);
originalNumber /= 10;
}
if(result == number)
System.out.println(number + " is an Armstrong number.");
else
System.out.println(number + " is not an Armstrong number.");
}
}
An Armstrong number is a number whose sum of cubes of digits is equal to the number itself.
For example:
153 = 1³+5³+3³
1+125+27
=153
Program:
import java. util.*;
class Armstrong
{
public static void main (string args [])
{
Scanner sc = new Scanner
int n, r, p, s=0, m;
System.out.println ("Enter a number");
n=sc.nextInt();
while
{
r=n%10
p=r*r*r;
s=s+p;
n=n/10;
}
if (m==s)
System.out.println (m+"is Armstrong");
else
System.out.println (m+"is not Armstrong");
}
}