Armstrong numbers between 1 to 1000 is a program to print all the possible Armstrong numbers between 1 to 1000.

What is Armstrong number?
Armstrong of a number is a sum of the Nth power of each digit in a number is equal to the number itself. Some Armstrong numbers are 0, 1, 153, 371, etc.

Formula to find Armstrong number
Number = Sum of Nth power of digits in number

Example: Number = 153
Then sum = 1 ^ 3 + 5 ^ 3 + 3 ^ 3
Sum = 1 + 125 + 27
Sum = 153
So the number is Armstrong number.

Algorithm for Armstrong number between 1 to 1000

  1. Declare variables. N, temp, sum
  2. Take a number user input. N
  3. Traverse from No= 1 till No
    while No>0
    i=num%10;
    sum+=i*i*i;
    num=num/10;
    if No == sum
    Print Armstrong number. No
    Else
    Continue

C program for Armstrong number between 1 to 1000

#include<stdio.h>

#include<math.h>

main()

{

int num,i,j,temp1,temp2,sum=0;

printf("Enter a number to know all armstrong number between them\n");

scanf("%d",&num);

printf("Armstrong numbers between 1 to %d are:\n",num);

for(i=1;i<=num;i++)

{

sum=0;
temp1=i;

temp2=i;

while(temp1>0)

{
j=temp1%10;
sum+=pow(j,3);
temp1=temp1/10;
}

if(sum==temp2)

{

printf("%d\n",sum);
}
}
}

Output :

Armstrong numbers between 1 to 1000

Write A Comment