Techknow Study

Armstrong Numbers

6:13:00 PM vikas 0 Comments Category :

Armstrong Numbers


An Armstrong number of three digits is an integer
such that the sum of the cubes of its digits is equal
to the number itself.
For example, 371 is an Armstrong number
since 3**3 + 7**3 + 1**3 = 371
.


FLOW CHART:





PROGRAM;-

#include<math.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int number,reminder,sum=0,temp;
clrscr();
printf("enter the number");
scanf("%d",&number); //for taking the number from user
printf("the number %d",number);
temp=number;
while(number>0)
{
reminder=number%10; //to separate 1's 10's so on place digit
sum=sum+pow(reminder,3);
number=number/10;
}
if(sum==temp)// compare the cube sum and number
{
printf(" is armstrong.");
}
else
{
printf(" is not armstrong.");
}
getch();
}

....................

Program Input and Output

There are six Armstrong numbers in the range of 0 and 999.

Armstrong number 1: 0
Armstrong number 2: 1
Armstrong number 3: 153
Armstrong number 4: 370
Armstrong number 5: 371
Armstrong number 6: 407
Thus The output for 153 on behalf of above program is:-

..........................................

RELATED POSTS

0 comments