Here is the program to calculate the Armstrong numbers, which will fall within the limit, starting from zero. The program expects the user to enter the upper limit.
Definition : Armstrong numbers are the integer numbers , where -the sum of third power of each digits – equals to the given number itself.
Logic : Here we traced the upper limit through a for loop, where in each of the iterations, we are checking if the sum of cubes of its digits equals that integer. If so, displaying the number.
The while loop is used to slice up a number, which, with a slight modification, can also help us in many other math related program segments. It needs to include the header “math.h”.
Program to find the armstrong numbers below a given number
#include<stdio.h>
#include<math.h>
void main()
{
int lim_up,n,dig,sum,num;
clrscr();
printf(“\n\n\t ENTER THE UPPER LIMIT…: “);
scanf(“%d”,&lim_up);
printf(“\n\n\t ARMSTRONG NUMBERS ARE…: “);
for(n=1;n<lim_up;n++)
{
sum = 0;
num = n;
while(num>0)
{
dig = num%10;
sum = sum+pow(dig,3);
num = num/10;
}
if(sum == n)
printf(“\n\n\t\t\t%d”,n);
}
getch();
}