Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

Discuss Kotters eight steps for leading organisational change.

Answered: 1 week ago