chore(CPlusPlus): add armstrong (#455)
Co-authored-by: Rahul Rajeev Pillai <66192267+Ashborn-SM@users.noreply.github.com>pull/482/head^2
parent
a25ec0ac56
commit
2cc1d5ffde
|
@ -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;
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue