Program to display Armstrong numbers between 1 to 500

//Program to display Armstrong numbers between 1 to 500
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,num,sum=0,rem,k;
  clrscr();
  printf("Armstrong numbers between 1 to 500 are\n");
  for(n=1;n<500;n++)
  {
     n=k;
     while(n>0)
     {
       rem=n%10;
       sum=sum+rem*rem*rem;
       n/10;
     }
     if(sum==k)
     printf("%d",k);
  }
   getch();
   return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

12 comments:

  1. in for loop first statement....what the k contains.i think it is k==n.

    ReplyDelete
  2. can u tell me the logic for this program

    ReplyDelete
  3. as u have done n=k;
    but this assignment is wrong actually this is such as k=n;
    also
    we have to make sum=0 after each value for n

    ReplyDelete
  4. ya, and also it is a forever loop...
    because every time value of n becomes zero for n/10..
    output is 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1.....

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

    ReplyDelete
    Replies
    1. #include
      #include
      void main()
      {
      int number,sum,temp,num=1;
      while(num<=500)
      {
      number=num;
      sum=0;
      while(number!=0)
      {
      temp=number%10;
      number=number/10;
      sum=sum+(temp*temp*temp);
      }
      if(sum==num)
      printf("%d",sum);
      ++num;
      }
      }

      Delete
  6. Code for Program for Number Conversion from Decimal to Binary, Decimal to Octal, Decimal to Hexa in one program. Do anyone help me??

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

    ReplyDelete