#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( );
}
#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