TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Checks whether a number is an Armstrong Number or not. More...
#include <cassert>
#include <cmath>
#include <iostream>
Go to the source code of this file.
Namespaces | |
namespace | dynamic_programming |
Dynamic Programming algorithms. | |
Functions | |
template<typename T > | |
bool | dynamic_programming::is_armstrong (const T &number) |
Checks if the given number is armstrong or not. | |
static void | tests () |
Self-test implementations. | |
int | main () |
Main function. | |
Checks whether a number is an Armstrong Number or not.
An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. For example: 153 is an Armstrong number since 153 = 1^3 + 5^3 + 3^3.
A few examples of valid armstrong numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084.
Armstrong numbers are also known as Narcissistic Numbers, as stated in Wikipedia.
Definition in file armstrong_number_templated.cpp.
int main | ( | void | ) |
Main function.
Definition at line 90 of file armstrong_number_templated.cpp.
|
static |
Self-test implementations.
Definition at line 71 of file armstrong_number_templated.cpp.