-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong_number.cpp
More file actions
43 lines (36 loc) · 823 Bytes
/
armstrong_number.cpp
File metadata and controls
43 lines (36 loc) · 823 Bytes
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
#include<iostream>
#include<cmath>
using namespace std;
// An Armstrong number (or narcissistic number) is a positive integer equal to the sum of its own digits,
// each raised to the power of the total number of digits in that integer
int count_digit(int n){
int count = 0;
while(n){
n /= 10;
count++;
}
return count;
}
void armstrong_num(int n){
int number = n;
int sum = 0;
int digit = count_digit(n);
while(n){
int m = n%10;
sum = sum + pow(m,digit);
n/=10;
}
if(sum == number){
cout << number << " is a armstrong number.\n";
}
else{
cout << number << " is not a armstrong number.\n";
}
}
int main(){
int number;
cout << "Number : ";
cin >> number;
armstrong_num(number);
return 0;
}