# Thread: Need help in C programming (too lazy)

1. ## Need help in C programming (too lazy)

I'm having some problem with my Computer Science lab. I really need some help! Here is the problem It should be written in C.

Problem: Given up to 30 integer values (all greater than 0) as input, find the smallest integer that is a multiple of more than half of the data input.

Example Execution #1:
Enter data #1 or -1 to exit: 1
Enter data #2 or -1 to exit: 2
Enter data #3 or -1 to exit: 3
Enter data #4 or -1 to exit: 4
Enter data #5 or -1 to exit: 5
Enter data #6 or -1 to exit: -1
Data entered: 1 2 3 4 5
The least majority multiple (3 of 5 values): 4

Example Execution #1 Explained:
Three values in the set {1, 2, 4} have 4 as a multiple.
A -1 is required to indicate the end of input when the number of data
values entered is less than 30.

Example Execution #2:
Enter data #1 or -1 to exit: 1
Enter data #2 or -1 to exit: 2
Enter data #3 or -1 to exit: 3
Enter data #4 or -1 to exit: 4
Enter data #5 or -1 to exit: 5
Enter data #6 or -1 to exit: 6
Enter data #7 or -1 to exit: -1
Data entered: 1 2 3 4 5 6
The least majority multiple (4 of 6 values): 6

Example Execution #2 Explained:
Three values in the set {1, 2, 4} have 4 as a multiple, but in the case of
an even number of data items a minimum of one more than half of the
number of data is necessary.
A -1 is required to indicate the end of input when the number of data
values entered is less than 30.

Example Execution #3:
Enter data #1 or -1 to exit: 1
Enter data #2 or -1 to exit: 11
Enter data #3 or -1 to exit: 4
Enter data #4 or -1 to exit: 6
Enter data #5 or -1 to exit: 8
Enter data #6 or -1 to exit: 2
Enter data #7 or -1 to exit: -1
Data entered: 1 11 4 6 8 2
The least majority multiple (4 of 6 values): 8

Example Execution #4:
Enter data #1 or -1 to exit: 11
Enter data #2 or -1 to exit: 12
Enter data #3 or -1 to exit: 13
Enter data #4 or -1 to exit: 14
Enter data #5 or -1 to exit: 15
Enter data #6 or -1 to exit: 16
Enter data #7 or -1 to exit: 17
Enter data #8 or -1 to exit: 18
Enter data #9 or -1 to exit: 19
Enter data #10 or -1 to exit: 20
Enter data #11 or -1 to exit: 1
Enter data #12 or -1 to exit: 2
Enter data #13 or -1 to exit: 3
Enter data #14 or -1 to exit: 4
Enter data #15 or -1 to exit: 5
Enter data #16 or -1 to exit: 6
Enter data #17 or -1 to exit: 7
Enter data #18 or -1 to exit: 8
Enter data #19 or -1 to exit: 9
Enter data #20 or -1 to exit: 10
Enter data #21 or -1 to exit: 21
Enter data #22 or -1 to exit: 22
Enter data #23 or -1 to exit: 23
Enter data #24 or -1 to exit: 24
Enter data #25 or -1 to exit: 25
Enter data #26 or -1 to exit: 26
Enter data #27 or -1 to exit: 27
Enter data #28 or -1 to exit: 28
Enter data #29 or -1 to exit: 29
Enter data #30 or -1 to exit: 30
Data entered: 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 21 22 23 24 25 26 27 28 29 30
The least majority multiple (16 of 30 values): 720

Example Execution #4 Explained:
When 30 integer values are entered the input should stop and the
program would continue. A -1 is not needed in this case.
Potential Problem: Once you have the program working for
this case, try it again substituting the last data item with a -1.

Example Execution #5:
Enter data #1 or -1 to exit: 23
Enter data #2 or -1 to exit: 37
Enter data #3 or -1 to exit: 41
Enter data #4 or -1 to exit: -1
Data entered: 23 37 41
The least majority multiple (2 of 3 values): 851

Example Execution #6:
Enter data #1 or -1 to exit: 59
Enter data #2 or -1 to exit: 61
Enter data #3 or -1 to exit: 67
Enter data #4 or -1 to exit: 31
Enter data #5 or -1 to exit: 37
Enter data #6 or -1 to exit: 41
Enter data #7 or -1 to exit: 43
Enter data #8 or -1 to exit: 47
Enter data #9 or -1 to exit: 53
Enter data #10 or -1 to exit: -1
Data entered: 59 61 67 31 37 41 43 47 53
Cannot find a least majority multiple less than or equal to 10000000!

Example Execution #6 Explained:
Do not search for a multiple that is greater than 10,000,000.
The whole program needs to display everything that is under Example Exectuion. The explanation is not necessary, it just explains what is going on to the programmer. I really need some help on this because the TA's at my college aren't willing to help because the professor is really strick on anybody helping for homework and projects. Please use simple coding because I will have to reprogram it. Thanks in advance for the help! I am a big newbie so please help!!! thanks a lot.

2. 1. It's not important.
2. You aren't asking for help, you're asking for someone to do it for you.
3. We don't do that.

Quzah.

3. Oh but it is important. Note the multiple instances of '!' in the subject line (as well as the 'please' and 'help,' -- two very helpful keywords for searching the forums at a later date). Also, observe the bold text of the entire post. Surely that denotes something of considerable gravity. And then there is the underlining and italics...

Ok, you were right. It's not important. At all.

But hey, the original post is like the new paradigm for all time useless 'do my homework' threads. Maybe we could get it stickied or something.

4. Hmm, what's the point of a TA if they can't help you? Although it's questionable if you want "help" or someone to do it for you.

5. Well that's convenient isn't it? Type up : "I'm having some problem with my Computer Science lab. I really need some help! Here is the problem It should be written in C." and copy paste the assignment here. That says a lot about how lazy you are. You could at least have written a pseudocode or discuss how you plan on doing this.

However, the "Help, yelp" stuff sounds to me like this is due tomorrow and you are out of luck my friend.

6. Fixed!

7. Originally Posted by Salem
Fixed!
lol nice work!

8. well i have to write my own code but i have no idea where to start. the point is. i am not going to use you guy's code because the professor scans it for cheating so im just getting an idea on how to start this thing. if you guys aren't willing to help me with the code can you guys atleast give me some clues on where to start?

9. Originally Posted by cwillygs
well i have to write my own code but i have no idea where to start. the point is. i am not going to use you guy's code because the professor scans it for cheating so im just getting an idea on how to start this thing. if you guys aren't willing to help me with the code can you guys atleast give me some clues on where to start?
Yes, that we can do. Start by figuring out the algorithm to solve the problem (i.e. if instead of getting the input from a computer I showed it to you on cards, how would you go about this problem in real life). Figure out these steps, then start coding and we will help you out with any problems that may arise. We will even help you with the algorithm but you need to put something on the table first. That's how it works.

10. Originally Posted by cwillygs
well i have to write my own code but i have no idea where to start. the point is. i am not going to use you guy's code because the professor scans it for cheating so im just getting an idea on how to start this thing. if you guys aren't willing to help me with the code can you guys atleast give me some clues on where to start?
This should get you started:

Code:
```int main(void)
{
return 0;
}```

11. ok. i think i have to use some kind of array right? i am not really really sure what an array is and how to implement it. i flipped through my text book and i still don't really know how to implement it. there are just some really simple examples but nothing sophisticated like this.

12. Originally Posted by cwillygs
ok. i think i have to use some kind of array right? i am not really really sure what an array is and how to implement it. i flipped through my text book and i still don't really know how to implement it. there are just some really simple examples but nothing sophisticated like this.
I told you before. Forget about arrays, forget about C and forget about programming. Imagine all you have is a list of N cards and on each card there is a number. N can be up to 30 but no more. The values on these cards can be in any order. You want to find a number that is the lowest multiple possible of at least half of these cards. How would you go about finding that number using your cards?

This is just math. Once you find how to solve this math problem you will have no trouble coding it. It should actually take you less than 10 minutes.

13. ok here is a wild guess. you multiply all those cards and then divide it by the greatest common denominator of all those numbers