CPP: add Happy Number solution (IEEEXtreme style)#215
CPP: add Happy Number solution (IEEEXtreme style)#215admirerr merged 3 commits intoadmirerr:mainfrom
Conversation
|
🎉 Welcome to Hacktoberfest 2025, @Mojirade18! 🎃 Thank you for your first contribution to our DSA repository! Here's what happens next: 🔍 Automatic Checks
📋 Next Steps🎁 What You Get
💡 Tips for Success
Welcome to the community! 🚀 |
🤖 Automated PR Status🔍 Code Validation✅ Passed - File naming and structure look good! 🧪 Compilation Tests❌ Failed - Please fix compilation errors and try again. 📋 Overall Status
This comment was generated automatically. Checks will re-run when you push new commits. |
|
🎉 Welcome to Hacktoberfest 2025, @Mojirade18! 🎃 Thank you for your first contribution to our DSA repository! Here's what happens next: 🔍 Automatic Checks
📋 Next Steps🎁 What You Get
💡 Tips for Success
Welcome to the community! 🚀 |
🤖 Automated PR Status🔍 Code Validation✅ Passed - File naming and structure look good! 🧪 Compilation Tests❌ Failed - Please fix compilation errors and try again. 📋 Overall Status
This comment was generated automatically. Checks will re-run when you push new commits. |
|
🎉 Welcome to Hacktoberfest 2025, @Mojirade18! 🎃 Thank you for your first contribution to our DSA repository! Here's what happens next: 🔍 Automatic Checks
📋 Next Steps🎯 Great job! Your code compiled successfully. Maintainers @admirerr and @kartikey2991 will review your PR soon. 🎁 What You Get
💡 Tips for Success
Welcome to the community! 🚀 |
🤖 Automated PR Status🔍 Code Validation✅ Passed - File naming and structure look good! 🧪 Compilation Tests✅ Passed - All code compiles successfully! 📋 Overall Status🎉 Ready for Review - Your PR has passed all automated checks! This comment was generated automatically. Checks will re-run when you push new commits. |
|
🎉 Welcome to Hacktoberfest 2025, @Mojirade18! 🎃 Thank you for your first contribution to our DSA repository! Here's what happens next: 🔍 Automatic Checks
📋 Next Steps🎯 Great job! Your code compiled successfully. Maintainers @admirerr and @kartikey2991 will review your PR soon. 🎁 What You Get
💡 Tips for Success
Welcome to the community! 🚀 |
🤖 Automated PR Status🔍 Code Validation✅ Passed - File naming and structure look good! 🧪 Compilation Tests✅ Passed - All code compiles successfully! 📋 Overall Status🎉 Ready for Review - Your PR has passed all automated checks! This comment was generated automatically. Checks will re-run when you push new commits. |
|
Approved |
Problem Name: Happy Number
Category: Basics (Mathematics / Number Manipulation)
Language: C++
Description
A Happy Number is a number that eventually reaches 1 when replaced by the sum of the squares of its digits repeatedly.
If the process enters a cycle that does not include 1, the number is not happy.
This solution implements the Floyd’s Cycle Detection Algorithm to determine if a number is happy or not.
Input / Output
Input:
A single positive integer n.
Output:
Prints "YES" if n is a happy number, otherwise prints "NO".
Example:
Input:
19
Output:
YES
Approach
Compute the sum of squares of digits.
Use two pointers (tortoise & hare) to detect loops efficiently.
If the sequence reaches 1 → happy number.
If it enters a loop → not happy.
File Information
File Path: CPP/Basics/happy_number.cpp