Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer in C++ 1 Happy numbers A happy number is a natural number (non-negative integer) that eventually becomes 1 when iterated over the sum

image text in transcribed

Please answer in C++

1 Happy numbers A happy number is a natural number (non-negative integer) that eventually becomes 1 when iterated over the sum of squared digits function. For example, 28 is happy: 28 +22 +82 = 68 +62 +82 = 100+ 11 +02 + 02 = 1 V But 4 is unhappy (omitting intermediate results), as the chain of numbers led to the original number. 4 + 16 + 37 58 89 145 + 42 420 +4+... In fact, every unhappy positive number eventually converges with 4. Write a function bool isHappy (unsigned int n) that receives as an argument a non- negative integer n and returns true if n is happy. Examples: isHappy (4) returns false. isHappy (13) returns true. isHappy (28) returns true

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions