-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path47thProgram_Example_3.cpp
More file actions
49 lines (44 loc) · 1002 Bytes
/
Copy path47thProgram_Example_3.cpp
File metadata and controls
49 lines (44 loc) · 1002 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
44
45
46
47
48
49
/* ********
Armstrong Number :
A number is an Armstrong number if the sum of the cubes of its digits is equal to the
number itself.
*********/
#include<iostream>
using namespace std;
int calcPower(int,int); //function declaration
int main(){
cout << "Enter a range ";
int num;
cin >> num;
for(int i=1;i<num;i++){
int temp = i;
int temp2 = i;
int temp3 = i;
int s = 0;
int arm =0;
int m;
int n;
while(temp>0){
m = temp%10;
temp = temp/10;
s = s+1;
}
for(int j=1;j<=s;j++){
n = temp2%10;
arm = calcPower(n,s) + arm;
temp2 = temp2/10;
}
if(arm == temp3){
cout << arm << endl;
}
}
return 0;
}
//function definition
int calcPower(int base, int exponent){
int result = 1;
for(int i=0;i<exponent;i++){
result = result * base;
}
return result;
}