Check Armstrong Number1.start2. input n.3. n1:=n.4. let s := 0.5. r := n1%10.6. s:=s+ r*r*r.7. n1 :=n1/10.8. if n10 then goto step 5.9. if n=s then10. print "ARMSTRONG NO"11. else12.print "NOT ARMSTRONG NO"13. endThe above algorithm would check only the 3 digit numbers, if u need it for all digit numbers then u need to request me again. CHAO.

Login to rate this answer.

Would appreciate the Generic algoirthm for the problem :-)

Login to rate this answer.

**saurabh**
Answered On : Sep 16th, 2006

could you please send armstrong algo for the all digitsthnking yousaurabh

Login to rate this answer.

**jyoti**
Answered On : Sep 27th, 2006

simply add a do-while loop to it for (n>0) and it whould wor for all number of digits jyotiwww.jyoticlub.jaijyoti.com

Login to rate this answer.

in C#:public static bool isArmstrong(int intInteger){// Declarationsint Length, Total1, Temp;string strString = intInteger.ToString();Total1 = 0;//get length of numberLength = strString.Length;//iterate through each digit, get n power, add to sumfor (int i = 0; i <= Length - 1; i++){Temp = Convert.ToInt32(strString.Substring(i, 1).ToString());Total1 += Convert.ToInt32(System.Math.Pow(Convert.ToDouble(Temp), Convert.ToDouble(Length)));}if (Total1 == intInteger){return true;}else{return false;}}

Login to rate this answer.

First of all I would like to introduce to you with amstrong number.

Lets take an example: 153 which is amstrong number because 153 = (1*1*1) + (5*5*5) + (3*3*3) i.e. 153 = 1^3 + 5^3 + 3^3(where ^ indicates power i.e. 3^3 is 3*3*3)Now logic behind writing the program to check the amstrong number:1: initialize the number i.e. numy

Login to rate this answer.

**Kapil S Shinde**
Answered On : Feb 25th, 2014

Code

start

Accept num

noOfDigit=calculate number of digits //use counting digit function

while(num!=0)

{

remainder=inum%10;

sum=sum+pow(remainder,noOfDigit); //use power function from math.h header file

num=num/10;

}

if(sum==num)

return true

else

return false

stop

Login to rate this answer.

First, count up the number of digits in the candidate value; an easy way to do this is take the floor value of the log of the number and add 1 (for example, floor(log10(1234)) = 3, so 3 + 1 = 4 digits).
Then extract each digit (an easy way to do this is to use a remainder or modulus operation), raise it to the power of the number of digits, and sum the results together.
Compare this sum to your candidate value; if they're equal, then the candidate value is narcissistic. Attached is an example written in C that examines a single number or range of numbers using base 10, along with some sample output.

Code

/**

* This program analyzes a range of numbers to see if they are

* narcissistic or Armstrong numbers (sum of its own digits, each

* raised to the power of the number of digits) in base 10.

*

* The output is simply the number if it meets the necessary

* criteria.

*/

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <math.h>

/**

* Test a candidate value to see if it is narcissisitc.

* Returns true (1) or false (0).

*/

int test( long cand )

{

int digits = (int) log10( (double) cand ) + 1;

long sum = 0;

long temp = cand;

for ( int i = 0; i < digits; i++ )

{

int curdigit = temp % 10;

temp /= 10;

sum += (long) pow( (double) curdigit, digits );

}

return sum == cand;

}

/**

* Process the command line arguments; must provide

* a valid integer or range of integers.

*/

int getargs( int argc, char **argv, long *start, long *end )

{

int result = 1;

if ( argc < 2 )

{

result = 0;

}

else if ( argc >= 2 )

{

char *chk;

long val = strtol( argv[1], &chk, 0 );

if ( isspace( *chk ) || *chk == 0 )

*start = *end = val;

else

result = 0;

if ( argc > 2 )

{

val = (int) strtol( argv[2], &chk, 0 );

if ( isspace( *chk ) || *chk == 0 )

*end = val;

else

result = 0;

}

}

return result;

}

/**

* Main program; loop through the specified range

* of values and test each for narcissism; if

* the number is narcissistic, write it to

* standard output.

*/

int main( int argc, char **argv )

{

long start=0, end=0;

const char *usage = "USAGE: %s start [end]n";

if ( !getargs (argc, argv, &start, &end ))

{

fprintf( stderr, usage, argv[0] );

return EXIT_FAILURE;

}

for( long t = start; t <= end; t++ )

if ( test( t ))

fprintf( stdout, "%ld

", t );

return EXIT_SUCCESS;

}

[fbgo448@n9dvap997]~/prototypes/armstrong: gcc -o armstrong -std=c99 -pedantic -g -Wall -Werror armstrong.c -lm

[fbgo448@n9dvap997]~/prototypes/armstrong: ./armstrong 153

153

[fbgo448@n9dvap997]~/prototypes/armstrong: ./armstrong 154

[fbgo448@n9dvap997]~/prototypes/armstrong: ./armstrong 0 10000

0

1

2

3

4

5

6

7

8

9

153

370

371

407

1634

8208

9474

Login to rate this answer.