Question:

Write a C program to find all the Armstrong numbers from 1 to 1000 using for loop?

by  |  earlier

0 LIKES UnLike

 Tags:

   Report

2 ANSWERS


  1. int main()
           {
            int i,a,b,c,x,y;
            clrscr();
            for (i=0;i<=1000;i++)
              {
              c=i%10;
              x=i/10;
              b=x%10;
              x=x/10;
              a=x%10;
              y=(a*a*a)+(b*b*b)+(c*c*c);
              if (i==y)
              printf("%d',i);
              }
            getch();      
            }


  2. 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;
    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions