NOTE: I have to use two integer user-defined functions
The first integer function should have two parameters, both of them integers. One parameter will be a
counter variable while the other parameter will be the number to be multiplied. For
example, if you are trying to find the common multiples for 7 and 9 as above some of the
calls to this function would look like this (values substituted for variables):
val1 = multiple(1, 7) //val1 would then be 7
val2 = multiple(1, 9) //val2 would then be 9
val1 = multiple(2, 7) //val1 would then be 14
val2 = multiple(2, 9) //val2 would then be 18
.
.
.
val1 = multiple(7, 7) //val1 would then be 49
val2 = multiple(7, 9) //val2 would then be 63
val1 = multiple(8, 7) //val1 would then be 56
val2 = multiple(8, 9) //val2 would then be 72
This is the only thing this function does. Multiply the two parameters and return the result to the calling function. The second function requires four parameters, the two numbers you are trying to find the common multiples for and the current values of val1 and val2 above. Val1 and Val2 simply represent the current multiple for the respective number. You will only find the
next multiple for val1 or val2 if the current value is the smaller of the two values. For example, if val1 = 7 and val2 = 9 then you would make a call to multiple(2, 7) to get the next multiple of 7. This would now necessitate a call to multiple(2, 9) and so on. This should be given you visions of a while loop. This function is not simple and will require some thought to figure out. Please work it out thoroughly. Hint: You will need a variable to indicate whether to continue looping or to stop looping (ie. val1 = val2)
Everything else happens in main(). Your two functions will simply do the math. (NO
OUTPUT or INPUT). All of your output will be in main().
THIS IS HOMEWORK. Please read the rules of this board - we can't help you with homeword per se, other than to point out specific errors in code that you wrote, or help you on a SPECIFIC question if you are stuck. Give it the old college try and post again when you are stuck on a specific part - you could at least write the functions - they are pretty trivial...
You have already provided far more infomation than is required to solve this problem.
Hint: The least common multiple of two numbers is the simply product of the two numbers. To find successive multiples you simply multiply that product by the desired multiple. One for the first, two for the second, three for the third, etc...
Look at your own examples.
>> val2 = multiple(7, 9) //val2 would then be 63
This is simply multiplying seven by nine. You also posted a sequence of numbers that are multiples of sixty-three.
>> 63 126 189 252 315 378 441 504 567 630...
Try dividing the numbers in this sequence by sixty-three. The results will be,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
Study these results, you should not have much trouble building a loop that can spit out these values.
Exceter
0
PurduePhiMuAuthor Commented:
Sorry for all the trouble. Thanks Exceter, apparently I'm just an idiot.
>> Sorry for all the trouble. Thanks Exceter, apparently I'm just an idiot.
It was no trouble. Remember, the only stupid question is the one you don't ask.
Exceter
0
Featured Post
Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.