Question: I am only given one hour to code this. [NOTE : NO arrays, pointers, recursion and strings should be used in this code.] 1) How

 I am only given one hour to code this. [NOTE :

NO arrays, pointers, recursion and strings should be used in this code.]

I am only given one hour to code this. [NOTE : NO arrays, pointers, recursion and strings should be used in this code.] 1) How do I go about doing this is under an hour? Please include some thought processes. 2) What's the best way to savage the maximum amount of marks if I don't complete this in under an hour?

Exercise 2: Happy Number 50 marks] Problem Statement For a positive integer S, if we sum up the squares of all the digits in S, we get another (possibly different) integer S1. If again, we sum up the squares of all the digits in S, we get yet another integer S2. We can repeat this process as many times as we want to get more integers. It has been proven that the integers generated in this way always eventually reach one of the 10 numbers 0, 1, 4, 16, 20, 37, 42, 58, 89, or 145. Particularly, a positive integer S is said to be happy if one of the integers generated this way is 1. For example, starting with 7 gives the sequence 17,49, 97, 130, 10, 1l, so 7 is a happy number. In this exercise, you are to write a program to compute and compare the number of happy numbers in two given ranges. For example, given two ranges [1, 10] and [2, 11], your program should be able to compute that there are 3 happy numbers (1, 7 and 10) in the first range and 2 (7 and 10) in the second. It should also be able to tell that there are more happy numbers in the first range than the second. Your program should read in four integers, which represent the lower bounds and upper bounds of the two ranges (both inclusive), compute the numbers of happy numbers in each range, and then print messages stating the numbers of happy numbers as well as which range has more happy numbers. You may assume that the input is valid (i.e., the integers are all positive and the lower bounds are no bigger than the upper bounds). Write on the skeleton file happy.c given to you. You need to include one function: * int computeHappyNumbers(int lower, int upper) which takes in two integers lower and upper, and returns the number of happy numbers in the range [lower, upper] You may define additional functions as needed. Check sample runs for input and output format

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!