Skip to content

Commit 28c68c2

Browse files
Create 7Armstrong.cpp
1 parent 2808129 commit 28c68c2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

7Armstrong.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
int main() {
7+
// Write C++ code here
8+
// 153=1^3+5^3+3^3; is called armstrong number
9+
int n;
10+
cin>>n;
11+
int num=n;
12+
int arr[100];
13+
int i=0;
14+
while(n>0){
15+
arr[i]=n%10;
16+
n=n/10;
17+
i++;
18+
}
19+
int sum=0;
20+
for(int j=i-1;j>=0;j--){
21+
sum=sum+pow(arr[j],3);
22+
}
23+
24+
cout<<sum;
25+
cout<<n;
26+
if(sum==num){
27+
cout<<"yes";
28+
}
29+
else{
30+
cout<<"no";
31+
}
32+
return 0;
33+
}

0 commit comments

Comments
 (0)