// ARMSTRONG NUMBER
# include <stdio.h>
void main()
{
int n,temp,r,sum=0;
printf("Enter any number : ");
scanf("%d",&n);
temp = n;
while (n!=0)
{
r = n%10;
sum = sum + (r*r*r);
n = n/10;
}
if(sum==temp)
{
printf("Number is Armstrong");
}
else
{
printf("Number is not Armstrong");
}
}
// ARMSTRONG NUMBER SERIES
# include <stdio.h>
void main()
{
int i,temp,sum=0,r,lim;
printf("Enter the limit : \n");
scanf("%d",&lim);
printf("Armstrong Numbers between 1 to %d are :\n",lim);
for(i=1;i<=lim;i++)
{
temp = i;
while(temp!=0)
{
r = temp%10;
sum = sum + (r*r*r);
temp = temp/10;
}
if(i==sum)
printf("%d ",i);
sum = 0;
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.