Thursday 26 January 2012

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

#include<stdio.h>
#include<conio.h>
void 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( );
}



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

No comments:

Post a Comment