Computer Science, asked by shivaswamy6, 9 months ago

WAP
to accept a number and check if it is a
Armstrong number or no​

Answers

Answered by manavjaison
1

Heya friend !

First of all,

Let us see what actually an Armstrong number is :-

Let the number be 123

Now, an armstrong number is where the number of the digits in that number raised to each number should be equal to the number

For this,

if 1^{3} +  2^{3} + 3 ^{3} = 123 , it is armstrong number, which is not true.

Now, let's consider the number 371.

So, there are total 3 digits in this number. So, if,

3^{3} + 7^{3} +1^{3}  = 371 it is armstrong number, which is true

Now, let us move on to the program

                        SOURCE CODE

# to check an Armstrong number of 3 digits

n = eval(input('Enter any number to check :'))

sum = 0

temporary = n

while n!=0:

   r=n%10

   sum=sum+r**3

   n=n//10

if temporary == sum:

   print('The number is an armstrong number')

else:

   print('The number is not an armstrong number')

                               OUTPUT

Enter any number to check :371

The number is an armstrong number

>>>  

>>>  

Enter any number to check :123

The number is not an armstrong number

>>>

Thanks !

#BAL #answerwithquality

Answered by kavitasingh1234
2

\huge\boxed{\dag\sf\red{ANSWER}\dag}

import java.util.*;

class Armstrong

{

public static void main(String args[])

{

int n,k,s=0,r=0;

System.out.println("ENTER THE NUMBER");

n=sc.nextInt( );

k=n;

while(n>0)

{

r=n%10;

s=s+(r*r*r);

n=n/10;

}

if(s==k)

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

else

System.out.println("The number is not armstrong");

}

}

}

Similar questions