Skip to content

Commit

Permalink
armstrong number
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanish2409 committed Jul 27, 2021
1 parent 68b470d commit 1e4c10d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.out
.vscode
.cph
34 changes: 34 additions & 0 deletions armstrong_number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<iostream>
#include<math.h>

using namespace std;

int main() {
int n, n_copy;
int digits = 0;
int sum = 0;

cin>>n;

n_copy = n;

while (n_copy >= 1) {
digits++;
n_copy /= 10;
}

n_copy = n;

while (n_copy >= 1 ) {
sum += pow(n_copy%10, digits);
n_copy /= 10;
}

if(n == sum ){
cout<<n<<" is an armstrong number.";
}else {
cout<<n<<" is not an armstrong number.";
}

return 0;
}

0 comments on commit 1e4c10d

Please sign in to comment.