Program for Armstrong numbers

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();
}

Download exe and source code here.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in