Solved

# Lowest Common Multiples

Posted on 2003-03-05
Medium Priority
809 Views
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().
0
Question by:PurduePhiMu
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 2

Expert Comment

ID: 8078113
What exactly is the question?
0

LVL 6

Expert Comment

ID: 8080348
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...
0

LVL 8

Accepted Solution

Exceter earned 150 total points
ID: 8081080

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

>> 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

Author Comment

ID: 8088831
Sorry for all the trouble.  Thanks Exceter, apparently I'm just an idiot.
0

LVL 8

Expert Comment

ID: 8089034
>> 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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were smallâ€¦
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and infâ€¦
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
###### Suggested Courses
Course of the Month12 days, 17 hours left to enroll