-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP28LOOP.cpp
More file actions
44 lines (33 loc) · 814 Bytes
/
P28LOOP.cpp
File metadata and controls
44 lines (33 loc) · 814 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
// To check Armstrong number or not
// it is basically the sum of the cubes of the given no. whose result will be same as the given no.
// eg:153= 1^3+5^3+3^3= 153
#include <iostream>
#include<cmath>
using namespace std;
int main() {
int n=0,num,originalNum,remainder,power,result=0;
cout<<"enter any number: ";
cin>>num;
originalNum=num;
while (originalNum!=0)
{
originalNum /= 10;
++n;
}
originalNum=num;
while (originalNum !=0)
{
remainder=originalNum %10; // pow() returns a double value
power=round(pow(remainder,n)); // round() returns the equivalent int
result+=power;
originalNum /=10;
}
if (result==num)
{
cout<<num<<" Armstrong number";
}
else{
cout<<num<<" not an Armstrong number";
}
return 0;
}