Thread: Need help in C programming (too lazy)

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    4

    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.
    Last edited by Salem; 04-19-2010 at 10:22 PM. Reason: Font abuse removed

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    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.
    Last edited by kermit; 04-19-2010 at 08:17 PM.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    58
    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. #5
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    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. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Fixed!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by Salem View Post
    Fixed!
    lol nice work!

  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    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. #9
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by cwillygs View Post
    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. #10
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Quote Originally Posted by cwillygs View Post
    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;
    }
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  11. #11
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    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. #12
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by cwillygs View Post
    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. #13
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    ok here is a wild guess. you multiply all those cards and then divide it by the greatest common denominator of all those numbers
    Last edited by cwillygs; 04-20-2010 at 12:26 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lazy allocation and *alloc()
    By Angus in forum Linux Programming
    Replies: 16
    Last Post: 09-08-2009, 01:01 PM
  2. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  3. lazy delete
    By kuwait in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2003, 02:45 PM
  4. Programmers getting lazy?
    By Travis Dane in forum A Brief History of Cprogramming.com
    Replies: 40
    Last Post: 02-19-2003, 07:04 PM
  5. IT people - weird genius or simply narrow-minded, antisocial, lazy people
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-11-2001, 05:00 AM