An Armstrong number is a number such that the sum of its digits raised to the third power is equal to the number itself. Write a program to check if an integer k is an Armstrong Number or Not.
Answers
Answered by
0
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is ... such that the sum ! of its digits raised to the third power is equal to the number !
Answered by
0
the number we want to check for armstrong is k in the following program.
import java.util.*;
class armstrong
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int s=0,d,di;
System.out.println("enter a no.");
int k=sc.nextInt();
int x=k;
while(x!=0)
{
d=x%10;
di=d*d*d;
s=s+di;
x=x/10;
}
if(s==k)
System.out.println("armstrong");
else
System.out.println("not armstrong");
}
}
Hope it helps!!!^_^
please mark me as the brainliest!!!!!
Similar questions