c program to find and print all armstrong number between 1 to 500

Armstrong numbers are:

Input :say value is 370.
When doing calculation for armstrong number:
370 is equal to (3*3*3)+(7*7*7)+(0*0*0) so output is 27+343+0 = 370
If input value is similar with output which is 370==370, then 370 is called an armstrong no.

#include
#include
void main()
{
  int number, j, remain;
  int cube=0, sum; 
  printf("\n Armstrong numbers between the limit from 1 to 500 are: \n"); 
  for(number=0;number<=999;number++)   
  {     
  	sum=0;
	j=number;     
	while(j>0)
    {
      remain=j%10;
      cube=remain*remain*remain;
      sum=sum+cube;
      j=j/10; 
    }
     if(number==sum)
     printf("\n%d is an armstrong no.",number);    
  }
     getch();
}

Ouput:

Armstrong numbers between the limit from 1 to 500 are:
1 is an armstrong no.
153 is an armstrong no.
370 is an armstrong no.
371 is an armstrong no.
407 is an armstrong no.

Leave a Reply

error: Content is protected !!
%d bloggers like this: