Armstrong numbers

4,824 views 11 slides Feb 26, 2017
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

What is Armstrong Numbers? Explanation with examples & programs in C language.


Slide Content

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("\n\n\nDo 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("\n\nArmstrong numbers between 1 to %ld are\n\n",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("%ld\t",temp);
}
}
printf("\n\n\nDo 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