number_of_digits(
intnum) {
44 // If the number is less than 0, then it is not an armstrong number. 51 // Finding the total number of digits in the number 52 inttotal_digits = number_of_digits(number);
55 // Finding each digit raised to the power total digit and add it to the 57 sum+=
static_cast<int>(std::pow(rem, total_digits));
60 returnnumber ==
sum;
68 // is_armstrong(370) returns true. 70 // is_armstrong(225) returns false. 72 // is_armstrong(-23) returns false. 74 // is_armstrong(153) returns true. 76 // is_armstrong(0) returns true. 78 // is_armstrong(12) returns false. 81std::cout <<
"All tests have successfully passed!\n";
89 test();
// run self-test implementationsstatic void test()
Self-test implementations.
int main()
Main function.
bool is_armstrong(const T &number)
Checks if the given number is armstrong or not.
T sum(const std::vector< std::valarray< T > > &A)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4