ARMSTRONG
NUMBERS
By: Tarun Sharma
(Lecturer Computer Science)
Contents
What is Armstrong Number? ................................................................................. 1
Examples of Armstrong Numbers .......................................................................... 2
Programs of Armstrong Numbers .......................................................................... 4
Program for Check a Single Armstrong Number.................................................. 4
Program for Check Armstrong Numbers between limit ...................................... 6
Armstrong Numbers Tarun Sharma
P a g e | 1
What is Armstrong Number?
An Armstrong number is any number of n digits which is equal to the sum of nth
power of digits in the number. Generally in most programming cases we consider
numbers from 000 to 999 that is 3 digit numbers. Thus, we also define Armstrong
number is any number of 3 digits as sum of cubes of digits in number.
Let us consider an example:
If ‘XYZ’ is a three digit Armstrong number, then
(X^3) + (Y^3) + (Z^3) = XYZ
If 'XYZA' is a four digit Armstrong number, then
(X^4)+(Y^4) + (Z^4) + (A^4) = XYZA and
If 'ABCDE' is a five digit Armstrong number then
(A^5) + (B^5) + (C^5) + (D^5) + (E^5) = ABCED and likewise.
Armstrong Numbers Tarun Sharma
P a g e | 2
Examples of Armstrong Numbers
Armstrong Numbers between different nth numbers of digits:
Between 1 to 9
Where n=1:
There are 9 single digit Armstrong numbers and they are 1-9.
Between 10 to 99
Where n=2:
There are no two digit Armstrong numbers.
Between 100 to 999
Where n=3:
There are 3 three digit Armstrong numbers and they are,
153 = 1^3 + 5^3 + 3^3 = 1+125+27 = 153
370 = 3^3 + 7^3 + 0^3 = 27+343+0 = 370
371 = 3^3 + 7^3 + 1^3 = 27+343+1 = 371
407 = 4^3 + 0^3 + 7^3 = 64+0+343 = 407
Between 1000 to 9999
Where n=4:
There are 4 four digit Armstrong numbers and they are:
1634 8208 9474
Armstrong Numbers Tarun Sharma
P a g e | 3
Between 10000 to 99999
Where n=5
There are 5 five digit Armstrong numbers and they are,
54748 92727 93084
Between 100000 to 999999
Where n=6:
There are 6 Six digit Armstrong numbers and they are,
548834
Between 1000000 to 9999999
Where n=7:
There are 7 Seven digit Armstrong numbers and they are,
1741725 4210818 9800817 9926315
Between 10000000 to 99999999
Where n=8:
There are 8 Eight digit Armstrong numbers and they are,
24678050 24678051 88593477
There are only 88 Armstrong numbers and the largest Armstrong number is a 39
digit number which is "115,132,219,018,763,992,565,095,597,973,971,522,401".
Armstrong Numbers Tarun Sharma
P a g e | 4
Programs of Armstrong Numbers
Solution of Armstrong Numbers in C Programming Language:
Program for Check a Single Armstrong Number
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
long int n, a,m, c, t, temp, p,i;
char ch;
clrscr();
printf("Enter Your Number:");
scanf("%ld",&n);
temp=t=n; m=0, p=1,c=0,a=0;
while(t>0)
{
c++;
t=t/10;
}
while(n>0)
{
m=n%10;
p=1;
Armstrong Numbers Tarun Sharma
P a g e | 5
for(i=1;i<=c;i++)
{
p=p*m;
}
a=a+p;
n=n/10;
}
if(a==temp)
{
printf("Number %ld is a Armstrong Number.",temp);
}
else
{
printf("Number %ld is Not a Armstrong Number.",temp);
}
printf("nnnDo you want to continue... if yes press 1 else any key..");
ch=getch();
if(ch=='1')
{
main();
}
else
{
exit(0);
}
Armstrong Numbers Tarun Sharma
P a g e | 6
getch();
}
Output:
Program for Check Armstrong Numbers between limit
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
long int n, a,m, c, t, temp, p,i,l,j;
char ch;
clrscr();
printf("Enter Your Limit:");
scanf("%ld",&l);
printf("nnArmstrong numbers between 1 to %ld arenn",l);
for(j=1;j<=l;j++)
{
temp=t=n=j;
Armstrong Numbers Tarun Sharma
P a g e | 7
m=0, p=1,c=0,a=0;
while(t>0)
{
c++;
t=t/10;
}
while(n>0)
{
m=n%10;
p=1;
for(i=1;i<=c;i++)
{
p=p*m;
}
a=a+p;
n=n/10;
}
if(a==temp)
{
printf("%ldt",temp);
}
}
printf("nnnDo you want to continue... if yes press 1 else any key..");
ch=getch();
if(ch=='1')
Armstrong Numbers Tarun Sharma
P a g e | 8
{
main();
}
else
{
exit(0);
}
getch();
}
Output:
Armstrong Numbers Tarun Sharma
P a g e | 9
Thank You

Armstrong numbers

  • 1.
  • 2.
    Contents What is ArmstrongNumber? ................................................................................. 1 Examples of Armstrong Numbers .......................................................................... 2 Programs of Armstrong Numbers .......................................................................... 4 Program for Check a Single Armstrong Number.................................................. 4 Program for Check Armstrong Numbers between limit ...................................... 6
  • 3.
    Armstrong Numbers TarunSharma P a g e | 1 What is Armstrong Number? An Armstrong number is any number of n digits which is equal to the sum of nth power of digits in the number. Generally in most programming cases we consider numbers from 000 to 999 that is 3 digit numbers. Thus, we also define Armstrong number is any number of 3 digits as sum of cubes of digits in number. Let us consider an example: If ‘XYZ’ is a three digit Armstrong number, then (X^3) + (Y^3) + (Z^3) = XYZ If 'XYZA' is a four digit Armstrong number, then (X^4)+(Y^4) + (Z^4) + (A^4) = XYZA and If 'ABCDE' is a five digit Armstrong number then (A^5) + (B^5) + (C^5) + (D^5) + (E^5) = ABCED and likewise.
  • 4.
    Armstrong Numbers TarunSharma P a g e | 2 Examples of Armstrong Numbers Armstrong Numbers between different nth numbers of digits: Between 1 to 9 Where n=1: There are 9 single digit Armstrong numbers and they are 1-9. Between 10 to 99 Where n=2: There are no two digit Armstrong numbers. Between 100 to 999 Where n=3: There are 3 three digit Armstrong numbers and they are, 153 = 1^3 + 5^3 + 3^3 = 1+125+27 = 153 370 = 3^3 + 7^3 + 0^3 = 27+343+0 = 370 371 = 3^3 + 7^3 + 1^3 = 27+343+1 = 371 407 = 4^3 + 0^3 + 7^3 = 64+0+343 = 407 Between 1000 to 9999 Where n=4: There are 4 four digit Armstrong numbers and they are: 1634 8208 9474
  • 5.
    Armstrong Numbers TarunSharma P a g e | 3 Between 10000 to 99999 Where n=5 There are 5 five digit Armstrong numbers and they are, 54748 92727 93084 Between 100000 to 999999 Where n=6: There are 6 Six digit Armstrong numbers and they are, 548834 Between 1000000 to 9999999 Where n=7: There are 7 Seven digit Armstrong numbers and they are, 1741725 4210818 9800817 9926315 Between 10000000 to 99999999 Where n=8: There are 8 Eight digit Armstrong numbers and they are, 24678050 24678051 88593477 There are only 88 Armstrong numbers and the largest Armstrong number is a 39 digit number which is "115,132,219,018,763,992,565,095,597,973,971,522,401".
  • 6.
    Armstrong Numbers TarunSharma P a g e | 4 Programs of Armstrong Numbers Solution of Armstrong Numbers in C Programming Language: Program for Check a Single Armstrong Number #include<stdio.h> #include<conio.h> #include<math.h> #include<stdlib.h> void main() { long int n, a,m, c, t, temp, p,i; char ch; clrscr(); printf("Enter Your Number:"); scanf("%ld",&n); temp=t=n; m=0, p=1,c=0,a=0; while(t>0) { c++; t=t/10; } while(n>0) { m=n%10; p=1;
  • 7.
    Armstrong Numbers TarunSharma P a g e | 5 for(i=1;i<=c;i++) { p=p*m; } a=a+p; n=n/10; } if(a==temp) { printf("Number %ld is a Armstrong Number.",temp); } else { printf("Number %ld is Not a Armstrong Number.",temp); } printf("nnnDo you want to continue... if yes press 1 else any key.."); ch=getch(); if(ch=='1') { main(); } else { exit(0); }
  • 8.
    Armstrong Numbers TarunSharma P a g e | 6 getch(); } Output: Program for Check Armstrong Numbers between limit #include<stdio.h> #include<conio.h> #include<math.h> #include<stdlib.h> void main() { long int n, a,m, c, t, temp, p,i,l,j; char ch; clrscr(); printf("Enter Your Limit:"); scanf("%ld",&l); printf("nnArmstrong numbers between 1 to %ld arenn",l); for(j=1;j<=l;j++) { temp=t=n=j;
  • 9.
    Armstrong Numbers TarunSharma P a g e | 7 m=0, p=1,c=0,a=0; while(t>0) { c++; t=t/10; } while(n>0) { m=n%10; p=1; for(i=1;i<=c;i++) { p=p*m; } a=a+p; n=n/10; } if(a==temp) { printf("%ldt",temp); } } printf("nnnDo you want to continue... if yes press 1 else any key.."); ch=getch(); if(ch=='1')
  • 10.
    Armstrong Numbers TarunSharma P a g e | 8 { main(); } else { exit(0); } getch(); } Output:
  • 11.
    Armstrong Numbers TarunSharma P a g e | 9 Thank You