0
2.7kviews
Write a function to check whether the given number is Armstrong number or not.

An Armstrong number is a number in which sum of cube of its all digits is equal to number itself. For example 371 is an Armstrong number, since $3^3 + 7^3 + 1^3 = 371$. Use an\bove function to generate all Armstrong numbers between 1 to 1000.


1 Answer
0
145views
#include(stdio.h)
#include(conio.h)

void armstrong(int a)
 {
  int temp,sum,rem;
  temp=a;
  sum=0;
  while(temp>0)
  {
   rem=temp%10;
   sum=sum+(rem*rem*rem);
   temp=temp/10;
  }
  if(a==sum)
  printf("%d",a);
  else
  continue;
 }

void main( )
{
int no;
clrscr( );
printf("Armstrong numbers between 1 and 1000 are:\n");
for(no=1; no<=1000; no++)
{
armstrong(no);
}
getch( );
}

Output:
Armstrong numbers between 1 and 1000 are:
1
153
370
371
407
Please log in to add an answer.