C Program For Armstrong Numbers Between 1 to 500
Write a C program to print armstrong numbers between 1 and 500.
Program to Print Armstrong Numbers Between 1 to 500
/* Aim: Write a program to display all Armstrong numbers between 1 and 500.
(Example: 153 = 1*1*1 + 5*5*5 + 3*3*3) */
#include<stdio.h>
int main()
{
int original,num,sum,r,n,i,a,b,temp,temp1;
printf("\n Enter the range a to b:- ");
scanf("%d%d",&a,&b);
printf("\n");
for(i=a;i<=b;i++)
{
original=i;
temp=i;
temp1=i;
sum=0;
while(temp1>0)
{
num/=10;
n++;
}
while(temp>0)
{
r=temp%10;
sum=sum+pow(r,n);
temp/=10;
}
if (original==sum)
{
printf(" %d",sum);
}
}
return 0;
}
Output:
Enter the range a to b:- 1 500 1 153 370 371 407