Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Mathematically, given a number , we can define a sequence , , ... where is the sum of the squares of the digits of . nis happy if and only if there exists isuch that .

Here is an example:

First, take each digit of any positive integer, square them and add them together. We will use the number nineteen as an example:

19 → 12 + 92 = 82

Then take each digit of this number, square them and add them together:

82 → 82 + 22 = 68

And repeat until the result is 1:

68 → 62 + 82 = 100

100 → 12 + 02 + 02 = 1

So when the sum of the squares of the digits in the last member in the sequence starting with neventually reduces to 1, is happy.

Additionally:

If a number is happy, then all members of its sequence are happy. If a number is unhappy, all members of its sequence are unhappy.

The above example sequence: 19, 82, 68, 100 is happy, and so all of the terms within the sequence are also happy.

Write a program that determines which numbers produce a happy sequence, within a series of test numbers.

The user will provide a first number to test and a last number to test. The program will test the numbers starting with the first number, incrementing by one, and repeating until the last number.

Program Implementation Requirements:

1. Tell the user what the program does before prompting for input.

2. mainwill call a user-defined function to read the first and last numbers for the range to test from the user.

- Theuser-defined function will:

o Separately read and validate each number. Both the first and last numbers must be at least 1 and can be up to 9999 (remember to define constants for these values!)

If the first number is not in the correct range, issue an error message and then re-prompt until the number entered is valid.

oThe last number cannot be smaller than the first number.

If the last number is not in the correct range or is smaller than the first number, issue an error message and then re-prompt until the number entered is valid.

o Pass back both values to main using reference parameters.

3. mainwill start with the first number as the test number, and loop until all numbers including the last number have been tested. Each time the loop runs, main will:

o Call a user-defined function to test if the number is happy.

o Display the results (whether the sequence is happy or unhappy), and pause so the results can be read by the user.

o Increment the test number.

- Theuser-defined function to test whether a number is happy must implement nested loops, as follows:

o A test number will be passed into the function.

o The function's outer loop will test the number, as follows:

o Use an inner loop to compute the sum of the squares of the digits in the current term. NOTE: You must use a loop, so this program will still work for larger numbers, if the maximum value of the last number constant is modified.

o Count and display each term.

o Each term displayed should be formatted to a width of 8, and 10 terms should be displayed per line.

o Repeat with the sum of the squares of the digits in the current term becoming the next term to test, until it is determined:

The test number is happy (when the sum of the square of the digits is 1)

The test number is unhappy (when 50 terms have been computed, without reaching 1).

o After the outer loop exits, the function shall display the number of terms in the sequence.

o A booleanvalue will be returned to main, indicating whether the displayed sequence is happy or not.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91376548
  • Price:- $50

Guranteed 36 Hours Delivery, In Price:- $50

Have any Question?


Related Questions in Programming Language

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As