Sunday, August 7, 2011

Armstrong numbers upto a given number

#include<stdio.h>
#include<math.h>
void main()
{
int num,sum,lim,dig,temp;
clrscr();
printf("Enter the limit :");
scanf("%d",&lim);
printf("\nArmstrong num upto %d are :\n",lim);
for(num=1;num<=lim;++num)
   {
   for(temp=num,sum=0;temp>0;temp/=10)

      {
      dig=temp%10;
      sum+=pow(dig,3);
      }
      if(num==sum)
printf("%d\n",num);
   }
getch();
}

No comments:

Post a Comment