/* WAP TO PRINT AND COUNT ARMSTRONG NO.S FROM 1 TO 1000.
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
int n;
int d,sum;
int count=0;
clrscr();
printf("\nArmstrong no.s from 1 to 1000 -->\n\n\t\t");
num=1;
while(num<1000)
{
n=num;
sum=0;
while(n>0)
{
d=n%10;
sum+=d*d*d;
n=n/10;
}
if(num==sum)
{
printf("%d\t",num);
count++;
}
num++;
}
printf("\n\nTotal no. of Armstrong no.s from 1 to 1000 = %d",count);
getch();
}
No comments:
Post a Comment