A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/de/d1e/armstrong__number_8cpp_source.html below:

TheAlgorithms/C++: math/armstrong_number.cpp Source File

28int

number_of_digits(

int

num) {

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 int

total_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 return

number ==

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. 81

std::cout <<

"All tests have successfully passed!\n"

;

89 test

();

// run self-test implementations

static 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