Subscribe

RSS Feed (xml)

Monday, August 3, 2009

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

17 comments:

  1. 2,3,4,5,6,7,8,9 are also armstrong numbers

    ReplyDelete
    Replies
    1. No if we cube 2 we get 8 and 8=2 so 2 is not armstrong no and all these no are not armstrong no except 1.

      Delete
    2. are madam ki madam se padh ki aayi ho...

      Delete
  2. y cant 2,3,4,5,6,7,8,9 be an armstrong numbers

    ReplyDelete
  3. why temp variable used in armstong number

    ReplyDelete
  4. waste,1 is armstrong,and program can be compiled using two while loops

    ReplyDelete
  5. armstrong number means cube of all digits.

    ex: 153
    1^3 + 5^3 + 3^3
    1+125+27=153

    ReplyDelete
  6. it is not proper program to understand and write it well and post the correct program to me at nanduk371@gmail.com

    ReplyDelete
  7. it should be
    if(sum==temp)
    printf("%d\n",temp);

    ReplyDelete
  8. thanx a lot for ua support sir!!! ths site is realy vry help ful for me as m pursuing mah B.Tech...... i was in search of this kinda site 4m many days!!!

    ReplyDelete
  9. armstrong number
    example:
    1) ab=(a*a)+(b*b)
    2) abc=(a*a*a)+(b*b*b)+(c*c*c)
    3) abcd=(a*a*a*a)+(b*b*b*b)+(c*c*c*c)+(d*d*d*d)
    and so on

    ReplyDelete
  10. so the above program is wrong if there exist a two digit armstrong number

    ReplyDelete
  11. How do you personally browse for info for your fresh posts, which particular search networks do you often rely on?

    ReplyDelete
  12. can any one tell why my below program prints all Armstrong except 153??

    #include
    #include
    int main()
    {
    int num,a,c=0,d,e,f,g,min,max,sum=0;

    printf("Enter a min and max\n");
    scanf("%d %d",&min,&max);



    num=min;
    while(num<=max)
    { a=num;
    d=a;
    c=0;
    sum=0;
    while(a!=0)
    {
    c++;
    a=a/10;
    }
    while(d!=0)
    { g=d%10;
    f=pow(g,c);
    sum=sum+f;
    d=d/10;
    }
    if(sum==num)
    {
    printf("\n armstrog=%d\n",num);
    }
    num++;
    }
    return 0;
    }





    ReplyDelete
  13. According to definition 1,2,3,4,5,6,7,8,9 should be Armstrong numbers. Are they?

    ReplyDelete
  14. I think this program can help you better http://www.compprog.com/2014/02/write-program-to-find-first-1000.html

    ReplyDelete
  15. Thank you. nice post... very usefull...

    ReplyDelete