// prg to illustrate Armstrong numbers in between min and max values
#include<stdio.h>
void main()
{
int min,max,n,r,arm=0,temp;
printf("\n Enter min value :");
scanf("%d",&min);
printf("\n Enter max value :");
scanf("%d",&max);
printf("\n Armstrong number in the given range :");
for(n=min ; n<=max ; n++)
{
temp=n,arm=0;
while(temp != 0)
{
r = temp % 10;
temp = temp / 10;
arm = arm + (r * r * r);
}
if( n == arm )
printf("\n%d is an armstrong \n",n);
}
}
output:
#include<stdio.h>
void main()
{
int min,max,n,r,arm=0,temp;
printf("\n Enter min value :");
scanf("%d",&min);
printf("\n Enter max value :");
scanf("%d",&max);
printf("\n Armstrong number in the given range :");
for(n=min ; n<=max ; n++)
{
temp=n,arm=0;
while(temp != 0)
{
r = temp % 10;
temp = temp / 10;
arm = arm + (r * r * r);
}
if( n == arm )
printf("\n%d is an armstrong \n",n);
}
}
output:
No comments:
Post a Comment