Computer Science, asked by parthprajapati7500, 5 months ago

input multi digital number then check whether number is armstrong or not

Answers

Answered by ananyastudent964
2

Answer:

here it is....

Explanation:

class ArmstrongExample{

public static void main(String[] args) {

int c=0,a,temp;

int n=153;//It is the number to check armstrong

temp=n;

while(n>0)

{

a=n%10;

n=n/10;

c=c+(a*a*a);

}

if(temp==c)

System.out.println("armstrong number");

else

System.out.println("Not armstrong number");

}

}

Answered by TheUntrustworthy
1

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");

}

}

Similar questions