diff --git a/algorithms/CPlusPlus/Maths/armstrong.cpp b/algorithms/CPlusPlus/Maths/armstrong.cpp new file mode 100644 index 00000000..f61ced4f --- /dev/null +++ b/algorithms/CPlusPlus/Maths/armstrong.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; +int main () +{ + int a = 0, t, n, s, r, p, i, sum = 0; + cin >> n; + t = n; + while (t > 0) + { + t /= 10; + a++; + } + s = n; + while (s > 0) + { + r = s % 10; + p = r; + for (i = 1; i < a; i++) + { + p *= r; + } + sum += p; + s /= 10; + } + if (sum == n) + cout << n << " is an armstrong number."; + else + cout << n << " is not an armstrong number."; + return 0; +} diff --git a/algorithms/CPlusPlus/README.md b/algorithms/CPlusPlus/README.md index 184faf19..bd539d77 100644 --- a/algorithms/CPlusPlus/README.md +++ b/algorithms/CPlusPlus/README.md @@ -118,6 +118,7 @@ 2. [Prime Number](Maths/prime-check.cpp) 3. [Prime Sieve](Maths/prime-sieve.cpp) 4. [Fibonacci Series](Maths/fibonaccci-series.cpp) +5. [Armstrong Number](Maths/armstrong.cpp) # Recursion