An Armstrong number is an n-digit number whose sum of digits raised to the nth power equals the number itself.
Take, for example, the Armstrong number 153, which is a three-digit number; 1^3 + 5^3 + 3^3 equals 1 + 125 + 27, which equals 153.
A program to find Armstrong numbers between 1 and 500 is provided below.
#include<stdio.h>
#include<math.h>
int main()
{
int n,sum,i,t,a;
printf("\nThe Armstrong numbers in between 1 to 500 are : \n");
for(i = 1; i <= 500; i++)
{
t = i; // as we need to retain the original number
sum = 0;
while(t != 0)
{
a = t%10;
sum += a*a*a;
t = t/10;
}
if(sum == i)
printf("\n\t%d", i);
}
return 0;
}
Output:
The Armstrong numbers in between 1 to 500 are :
1
153
370
371
407
Note: also read about the Miscellaneous Program(reverse the case of input string)
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…