Writing a program that will determine the least common multiples of any two integers. The user will input the data like this:

How many common multiples do you want to find? 200

Please enter two numbers to find the least common multiples of: 7 9

Your two numbers are 7 and 9.

The least common multiples are:

63 126 189 252 315 378 441 504 567 630

693 756 819 882 945 1008 1071 1134 1197 1260

1323 1386 1449 1512 1575 1638 1701 1764 1827 1890

1953 2016 2079 2142 2205 2268 2331 2394 2457 2520

2583 2646 2709 2772 2835 2898 2961 3024 3087 3150

3213 3276 3339 3402 3465 3528 3591 3654 3717 3780

3843 3906 3969 4032 4095 4158 4221 4284 4347 4410

4473 4536 4599 4662 4725 4788 4851 4914 4977 5040

5103 5166 5229 5292 5355 5418 5481 5544 5607 5670

5733 5796 5859 5922 5985 6048 6111 6174 6237 6300

6363 6426 6489 6552 6615 6678 6741 6804 6867 6930

6993 7056 7119 7182 7245 7308 7371 7434 7497 7560

7623 7686 7749 7812 7875 7938 8001 8064 8127 8190

8253 8316 8379 8442 8505 8568 8631 8694 8757 8820

8883 8946 9009 9072 9135 9198 9261 9324 9387 9450

9513 9576 9639 9702 9765 9828 9891 9954 10017 10080

10143 10206 10269 10332 10395 10458 10521 10584 10647 10710

10773 10836 10899 10962 11025 11088 11151 11214 11277 11340

11403 11466 11529 11592 11655 11718 11781 11844 11907 11970

12033 12096 12159 12222 12285 12348 12411 12474 12537 12600

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().

How many common multiples do you want to find? 200

Please enter two numbers to find the least common multiples of: 7 9

Your two numbers are 7 and 9.

The least common multiples are:

63 126 189 252 315 378 441 504 567 630

693 756 819 882 945 1008 1071 1134 1197 1260

1323 1386 1449 1512 1575 1638 1701 1764 1827 1890

1953 2016 2079 2142 2205 2268 2331 2394 2457 2520

2583 2646 2709 2772 2835 2898 2961 3024 3087 3150

3213 3276 3339 3402 3465 3528 3591 3654 3717 3780

3843 3906 3969 4032 4095 4158 4221 4284 4347 4410

4473 4536 4599 4662 4725 4788 4851 4914 4977 5040

5103 5166 5229 5292 5355 5418 5481 5544 5607 5670

5733 5796 5859 5922 5985 6048 6111 6174 6237 6300

6363 6426 6489 6552 6615 6678 6741 6804 6867 6930

6993 7056 7119 7182 7245 7308 7371 7434 7497 7560

7623 7686 7749 7812 7875 7938 8001 8064 8127 8190

8253 8316 8379 8442 8505 8568 8631 8694 8757 8820

8883 8946 9009 9072 9135 9198 9261 9324 9387 9450

9513 9576 9639 9702 9765 9828 9891 9954 10017 10080

10143 10206 10269 10332 10395 10458 10521 10584 10647 10710

10773 10836 10899 10962 11025 11088 11151 11214 11277 11340

11403 11466 11529 11592 11655 11718 11781 11844 11907 11970

12033 12096 12159 12222 12285 12348 12411 12474 12537 12600

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().

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialIt was no trouble. Remember, the only stupid question is the one you don't ask.

Exceter

C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.