Armstrong number using awk command
November27
Armstrong number
Also known as narcissistic numbers, Armstrong numbers are the sum of their own digits to the power of the number of digits. As that is a slightly brief wording, let me give an example:
153 = 1³ + 5³ + 3³
Each digit is raised to the power three because 153 has three digits.
The below code is used to find out the Armstrong numbers upto 2000. you can simply increase the value in {1..2000}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | for i in {1..2000};do echo $i | awk '{a=0;l=length($0);for(i=1;i<=l;i++){a+=$i^l}if(a>$0)exit}$0==a{print}' FS= ; done 1 2 3 4 5 6 7 8 9 153 370 371 407 1634 |
Recent Comments