-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArmstrong Number.cpp
49 lines (47 loc) · 1004 Bytes
/
Armstrong Number.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include<cmath>
using namespace std;
/*
An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.
For instance, a 3 digit number will be considered an Armstrong number if the sum of the cubes of its digits is equal to the number itself.
For example, 153 is an Armstrong number,
as 1^3 + 5^3 + 3^3 = 153
Armstrong Numbers : 1,153,370,371,407,8208,9474
*/
int Armstrongcheck(int);
int main()
{
int num;
// cout<<"Enter a Number:";
cin>>num;
// for(num=1;num<=1000;num++)
if(Armstrongcheck(num) == 1)
cout<<num<<" is Armstrong Number."<<endl;
else
cout<<num<<" is Not Armstrong Number."<<endl;
return 0;
}
int Armstrongcheck(int num)
{
int n,sum,rem,digit=0;
float p;
n=num;
while(n!=0)
{
digit++;
n=n/10;
}
n=num;
sum=0;
while(n!=0)
{
rem=n%10;
p=pow(rem,digit);
sum+=p;
n=n/10;
}
if(sum==num)
return 1;
else
return 0;
}