Skip to content

Optimized the code of armstrong_number.cpp#3186

Open
TechWhiz42 wants to merge 1 commit into
TheAlgorithms:masterfrom
TechWhiz42:optimized_armstrong_number.cpp
Open

Optimized the code of armstrong_number.cpp#3186
TechWhiz42 wants to merge 1 commit into
TheAlgorithms:masterfrom
TechWhiz42:optimized_armstrong_number.cpp

Conversation

@TechWhiz42

Copy link
Copy Markdown

Description of Change

  • Fixed the edge case where 0 was treated as having 0 digits by correctly considering it a one-digit number.
  • Replaced floating-point exponentiation (std::pow) with an integer exponentiation helper function to avoid unnecessary floating-point operations.
  • Added additional self-test cases to improve test coverage for valid and invalid Armstrong numbers.
  • Removed the unused <cmath> header after eliminating std::pow().

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes: Improves correctness for the edge case of 0, replaces floating-point exponentiation with integer arithmetic, and expands the self-test suite.

@TechWhiz42

TechWhiz42 commented Jun 30, 2026

Copy link
Copy Markdown
Author

Hey people,
This is my very first contribution. Even if my contribution is not merged, please tell me how can I improve. That will be more than enough.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant