-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Meghna2080/master
Created Check_armstrong_number.cpp
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Program's_Contributed_By_Contributors/Check_armstrong_number.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include<iostream> | ||
#include<math.h> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int n,temp,remainder,x=0,ans=0; | ||
cout<<"Enter a number:"<<endl; | ||
cin>>n; | ||
temp=n; | ||
while(temp!=0){ | ||
temp=temp/10; | ||
x++; | ||
} | ||
temp=n; | ||
while(temp!=0) | ||
{ | ||
remainder=temp%10; | ||
int power=round(pow(remainder,x)); | ||
ans+=power; | ||
temp=temp/10; | ||
} | ||
if(ans==n) | ||
cout<<"Armstrong number"; | ||
else | ||
cout<<"Not an armstrong number"; | ||
return 0; | ||
} |