chore(CPlusPlus): add armstrong (#455)

Co-authored-by: Rahul Rajeev Pillai <66192267+Ashborn-SM@users.noreply.github.com>
pull/482/head^2
kumarsyadav2 2021-09-23 18:23:20 +05:30 committed by GitHub
parent a25ec0ac56
commit 2cc1d5ffde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,30 @@
#include <iostream>
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;
}

View File

@ -118,6 +118,7 @@
2. [Prime Number](Maths/prime-check.cpp) 2. [Prime Number](Maths/prime-check.cpp)
3. [Prime Sieve](Maths/prime-sieve.cpp) 3. [Prime Sieve](Maths/prime-sieve.cpp)
4. [Fibonacci Series](Maths/fibonaccci-series.cpp) 4. [Fibonacci Series](Maths/fibonaccci-series.cpp)
5. [Armstrong Number](Maths/armstrong.cpp)
# Recursion # Recursion