Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE CODE IN C DO NOT COPY Exercise 2. (50 points) Happy Numbers A happy number is a number defined by the following process: Starting

PLEASE CODE IN C DO NOT COPYimage text in transcribed

Exercise 2. (50 points) Happy Numbers A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1 . Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers. For example, 13 is a happy number since 12+32=1+9=1012+02=1+0=1 And 85 is an unhappy number since 82+52=64+25=8982+92=64+81=14512+42+52=1+16+25=4242+22=16+4=2022+02=4+0=442=1612+62=1+36=3732+72=9+49=5852+82=25+64=89,whichisarepeatedresult. It can be shown that if a number is an unhappy number, it will reach 4 in the above process. This can be used to check whether a number is an unhappy number. Our job is to write code to check whether a positive integer is a happy number. Part of the code is already given. As shown below, we only need to fill in the code under TODO. Note to print out the intermediate numbers to match the expected output. \#include \#include int main() \{ int n; printf ("n="); scanf ("%d", \&n ); int m=n; //TODO //add code below

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions