Write a C program to print all Armstrong numbers between 1 to 1000.


#include(stdio.h)
#include(conio.h)
int main( )
{
int no, temp, rem, sum;
clrscr( );
printf("Armstrong numbers between 1 and 1000 are:\n");
for(no=1; no<=1000; no++)
{
temp=no;
sum=0;
while(temp>0)
{
rem=temp%10;
sum=sum+(rem*rem*rem);
temp=temp/10;
}
if(no==sum)
printf("\n%d", no);
}
getch( );
return 0;
}

Output:
Armstrong numbers between 1 and 1000 are:
1
153
370
371
407

#vpsinghrajput

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

17 comments:

  1. Its really quiet helpful as i a new learner i t helps me a lot

    ReplyDelete
  2. I suppose Armstrong number are
    Sum of their own digits to the power of the number of digits
    So
    1,2,3,4,5,6,7,8,9
    All are Armstrong

    ReplyDelete
  3. the power is only 3(cube) and nothing else,,,:)

    ReplyDelete
  4. how to print total number.like here total number is 5

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. #include(stdio.h)
      #include(conio.h)
      int main( )
      {
      int no, temp, rem, sum,count=0;
      clrscr( );
      printf("Armstrong numbers between 1 and 1000 are:\n");
      for(no=1; no<=1000; no++)
      {
      temp=no;
      sum=0;
      while(temp>0)
      {
      rem=temp%10;
      sum=sum+(rem*rem*rem);
      temp=temp/10;
      }
      if(no==sum)
      {
      printf("\n%d", no);
      count++;
      }
      }
      printf("%d",count);
      getch( );
      return 0;
      }

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. What's the tem and temp plz suggest me

    ReplyDelete
    Replies
    1. Temp means another variable to store the n variable,rem is remainder,😆

      Delete