mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-03 18:50:56 +08:00
Showing 153 is not an Armstrong number. (#680)
* Update Armstrong Number.cpp * Update Armstrong Number.cpp * Update Armstrong Number.cpp * Update Armstrong Number.cpp * Rename Armstrong Number.cpp to armstrong_number.cpp * Update armstrong_number.cpp Showing 153 as not an Armstrong number. * Update armstrong_number.cpp
This commit is contained in:
committed by
Christian Clauss
parent
08451b1c4c
commit
f02bdb7390
21
dynamic_programming/armstrong_number.cpp
Normal file
21
dynamic_programming/armstrong_number.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Program to check whether a number is an armstrong number or not
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
|
||||
int main() {
|
||||
int n, k, d, s = 0;
|
||||
cout << "Enter a number:";
|
||||
cin >> n;
|
||||
k = n;
|
||||
while (k != 0) {
|
||||
d = k % 10;
|
||||
s += d * d * d;
|
||||
k /= 10;
|
||||
}
|
||||
if (s == n)
|
||||
cout << n << "is an armstrong number";
|
||||
else
|
||||
cout << n << "is not an armstrong number";
|
||||
}
|
||||
Reference in New Issue
Block a user