First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
First, review the definition of an Armstrong, or narcissistic, number:
"...is a number that is the sum of its own digits each raised to the power of the number of digits."
So, you need to count the digits (to know what power to use), and extract the individual digits. This can be done in several ways; for example, you might convert the number to a string. In Java:
String numberAsString = "" + number;
Now it should be easy to figure out the length of the String (use the .length() method), and to extract the individual digits - check the methods available for strings. Then you need to convert the digits back to numeric data.
Another way is to get one digit at a time, starting from the right, using the "%" operator.
For example, 153 % 10 is equal to 3. Divide the number, 153, by 10 (integer division), then repeat to get the remaining digits. You might store the digits to an array.
45
/*Program to find whether given no. is Armstrong or not. Example : Input - 153 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); int n = num; //use to check at last time int check=0,remainder; while(num > 0){ remainder = num % 10; check = check + (int)Math.pow(remainder,3); num = num / 10; } if(check == n) System.out.println(n+" is an Armstrong Number"); else System.out.println(n+" is not a Armstrong Number"); } }
<html> <head> <Script Language="JavaScript"> var a,n,b=0,t; n=parseInt(window.prompt("enter n","0")); t=n; while(n>0) { a=n%10; b=b+a*a*a; n=n/10; } if(b==t) { document.writeln("Armstrong no"); } else { document.writeln("Not an Armstrong no"); } </script> </head> </html>
Type your answer here... i think we should first enter 1 number then check it
[object Object]
8086 assembly language program to check wether given number is perfect or not
Avogadro's number is a constant. Therefore only one number is equal to Avogadro's number.
write a program in C to check whether a given number is apalindrome or not
Is the last digit 2, 4, 6, 8 or 0? If yes, it's even, else odd.
See whether the number is divisible by 2, and by all odd numbers up to the square root of the number. For numbers up to 100, it is enough to check the factors 2, 3, 5, and 7. For higher numbers you need to check more factors. For very large numbers (for example, hundreds of digits), more efficient methods are known, but those methods are also more complicated.
first we write start and then read number and after that check the number is totaly divide by 2 or not if number is totally divide by 2 then number is even else number is odd.
If it is even