21. Number is Armstonrg or not

       Armstorng no : If the sum of the digits of the cube of number is equal to original number then it is armstorng number .

      ex : take number n = 153;

          if  3*3*3 + 5*5*5 + 1*1*1 = 153 (i.e. same  number ,n )

          then, the number is Armstorng number.


 int n,r;
int sum=0;
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
int store = n // to store the number ;
while(n>0)
{
r=n%10;
sum=sum+r*r*r; //sum of the cuber of the number
n=n/10;
}
System.out.println(sum);
if (sum==store)
{
System.out.println(store +" is Armstrong no");
}
else
System.out.println(store + " is not Armstrong no");
}

23564

440

23564 is not Armstrong no


Process finished with exit code 0

          

Comments

Popular posts from this blog

the distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter.

CREATE UNIT CONVERTER APP

write a program to check whether a triangle is valid or not, when the threeangles of the triangle are entered through the keyboard. A triangle is valid if the sumof all the three angles is equal to 180 degrees