Write in C++. Do not use arrays or strings. 2. Happy Numbers: A number (>0) is called
Fantastic news! We've Found the answer you've been seeking!
Question:
Write in C++. Do not use arrays or strings.
Transcribed Image Text:
2. Happy Numbers: A number (>0) is called a happy number, if you start with the given number and arrive at 1 by repeating the following process (as illustrated in the below example): (a) compute the sum of the squares of given number digits (b) if the resultant value is 1, then the number is happy number, else execute point (a) for the newly produced number. Note that if a number is not a happy number, there will be an endless loop to this execution. Goal: In this question, you are required to write Function that checks whether the number entered by the user is happy number or not for 100 cycles/iterations only. Example: Assume a number 19 Number Computation 12 +92 82 +22 62 + 82 12 +02 +02 Result cycle/iterations 1 19 82 82 68 68 2 100 3 100 1 4 Stop computing further, as the Result obtained is 1. Hence, the number '19' , is a happy number. We achieved this in 4th cycles only. Function Prototype: bool isHappyNumber(int num); Example 01:** *marks: 02 Input: Number: 19 Output: Happy Number Example 02:** *marks: 02 Input: Number: 7 Output: Happy Number Example 03:*** Input: Number: 18 *marks: 02 Output: Sad Number Note: Take input and display output in main function. 2. Happy Numbers: A number (>0) is called a happy number, if you start with the given number and arrive at 1 by repeating the following process (as illustrated in the below example): (a) compute the sum of the squares of given number digits (b) if the resultant value is 1, then the number is happy number, else execute point (a) for the newly produced number. Note that if a number is not a happy number, there will be an endless loop to this execution. Goal: In this question, you are required to write Function that checks whether the number entered by the user is happy number or not for 100 cycles/iterations only. Example: Assume a number 19 Number Computation 12 +92 82 +22 62 + 82 12 +02 +02 Result cycle/iterations 1 19 82 82 68 68 2 100 3 100 1 4 Stop computing further, as the Result obtained is 1. Hence, the number '19' , is a happy number. We achieved this in 4th cycles only. Function Prototype: bool isHappyNumber(int num); Example 01:** *marks: 02 Input: Number: 19 Output: Happy Number Example 02:** *marks: 02 Input: Number: 7 Output: Happy Number Example 03:*** Input: Number: 18 *marks: 02 Output: Sad Number Note: Take input and display output in main function.
Expert Answer:
Answer rating: 100% (QA)
Here is the screenshot of the program code Screenshot of the output Text Format Code include using n... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
10,000.0 8,000.0 6,000.0 4,000.0 2,000.0 0.0 (2,000.0) (4,000.0) (6,000.0) (8,000.0) (10,000.0) (12,000.0) 01/Oct/17 01/Sep/17 Operating cash flow Investing cash flow Financing cash flow Monthly cash...
-
Joe and Liz are the directors of BuzzMe Pty Ltd, a mobile phone company. Joe had known that the company was in financial difficulties in December 2019 but had assured his fellow director it was just...
-
Write a C++ program that will compare two arrays to test for the same elements and multiplicity. To begin, populate the arrays with the input files, comFile1.txt and comFile2.txt. The elements in the...
-
Is CSCH3CO2 ionic or covalent ? Name it QUESTION 7 Is rubidium dichromate ionic or covalent ? Write its formula QUESTION 8 s copper m suhde soric or covaent write its formula QUESTION 9 Is vanadium...
-
As part of a Type C reorganization, Ash Corporation exchanges $250,000 of its voting common stock and $50,000 of its bonds for all of Texas Corporations assets. Texas liquidates, with each of its two...
-
(a) Determine the critical value for a right-tailed test of a population mean at the = 0.1 level of signicance with 22 degrees of freedom. (b) Determine the critical value for a left-tailed test of...
-
Cat Auto Tech. Corp. purchased 10,000 gift certificates from DeJesus. Cat Auto Tech. Corp., an Amoco gasoline station operator, contracted with DeJesus to make 10,000 gift certificates of various...
-
Since Jack believes that Work Center 3 is his bottleneck, he has asked you to do the following: (a) Calculate the percentage of planned output needed to complete the planned inputs (planned input +...
-
A Rolls-Royce Phantom weighing 2.49 x 104 N is traveling in the +x direction with an initial speed of 40.2 m/s when the driver hits the brakes. The car slows to a stop in 5.60 s. If the acceleration...
-
Update the trial balance for Kreg?s Moving Co. (Figure 4.27 on page 137) for October 31, 201X. Adjustment Data to Update Trial Balance 1. Insurance expired, $550. 2. Moving supplies on hand, $800. 3....
-
A wave has a speed of 1200 m/s and a wavelength of 3.3 m. What is its approximate frequency?
-
Compare between Invasive and modern non-invasive prenatal tests.
-
5. A consumer group hoping to assess customer experiences with auto dealer surveys 167 people who recently bought new cars; 3% of them expressed dissatisfaction with the salesperson. We want to learn...
-
Write a program to ask the user to enter number less than 5 5 using the below code as a skeloton. If the user enters greater than 5 , 5 , the program will loop to ask the user to enter the number...
-
1. What do you understand by the term "civil society" and what is its purpose? 2. What is the purpose of rights? 3. Define and give examples of the following type of rights: a. Civil b. Political c....
-
Consider a relation R with five attributes ABCDE. You are given the following dependencies: A B, BC E, and ED A. 1. List all keys for R. 2. Is R in 3NF? 3. Is R in BCNF? -
-
function HYBRIDSORT (A[0..n-1]) if n > 10 then B[0.. [n/2] 1] A[0..[n/2] 1] C[0..[n/2] -1] A[[n/2]..n 1] HYBRIDSORT (B[0..[n/2] 1]) HYBRIDSORT(C[0..[n/2] - 1]) MERGE(B[0.. [n/2] 1], C[0..[n/2] 1],...
-
Why is it important to understand the macro-environment when making decisions about an international retail venture?
-
You are given the following Laplace transform of the output y(t)of a system with input x(t)and Laplace transform X(s): (a) If x(t) = u(t), find the zero-state response y zs (t). (b) Find the...
-
Given the anti-causal signal x[n]= n u[n] (a) Determine its Z-transform X(z), and carefully plot the ROC when = 0.5 and = 2. For which of the two values of does X(e j ) exist? (b) Find the signal...
-
We are interested in the unit-step solu-tion of a system represented by the following difference equation y[n] = y[n 1] 0.5y[n 2] + x[n] + x[n 1] (a) Find an expression for Y(z). (b) Do a partial...
-
Beginning in the 1920s, Russian physicist Pyotr Kapitza or Kapitsa (18941984, Nobel laureate in physics 1978) measured the Paschen-Back effect to an accuracy of 1 percent to 3 percent in various...
-
Consider transitions from a \({ }^{2} D\) state to a \(2 P\) state in the strong field PaschenBack regime. List all allowed transitions and show that there are only three different spectral lines.
-
What is the longest wavelength of the Paschen series spectrum? Would it be visible to the human eye?
Study smarter with the SolutionInn App