A positive integer is called an Armstrong number if the sum of cubes of individual digit is equal to that number itself.
For example:
153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.
12 is not equal to 1*1*1+2*2*2 // 12 is not an Armstrong number.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n1,n2,i,r,s,k;
printf("Enter interval (two numbers): ");
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
s=0;
k=i;
while(k>0)
{
r=k%10;
s+=pow(r,3);
k=k/10;
}
if(i==s)
printf("%d\t",i);
}
getch();
No comments:
Post a Comment