Thread: arrays

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Question arrays

    Hi everyone....
    I have two questions for anyone who can help. This will help me prepare for my test in my C programming class.

    1.) Define an array of 12 reals. Then code the statements to calculate the sum of all the elements in this array. Display this total on the screen formatted and rounded to the nearest three decimal places. (define any variables needed)

    2.) Define an array of 6 strings of length 10. Then code the statements to loop 6 times prompting the user to enter a string of 10 or less characters and read the strings entered into the elements of this array. (define any variables needed)

    Thanks

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    ... and what exactly would you like help with? Have you tried answering them yourself first? If so, post what you've come up with and someone will let you know if you're going in the right direction.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    1)

    Code:
    int result, counter, numb[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
    counter = 0;
    
    while (counter < 12)
    {
    result += numb[counter];
    counter++;
    }
    
    printf("Result: %d", result);
    hmm...i think that should do the trick

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by stallion
    1)

    Code:
    int result, counter, numb[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
    counter = 0;
    
    while (counter < 12)
    {
    result += numb[counter];
    counter++;
    }
    
    printf("Result: %d", result);
    hmm...i think that should do the trick
    I'm sure they're going to just learn so much by having you do their homework for you. I and the rest of the regulars thank you from the bottom of our heart.

    Hm... did that sound sarcastic?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    at least you could give some example for them (not refer to real question).
    --->> at least they would know how to program in C

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Smile thank you stallion

    Hi Stallion....

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    quzah, i'm not sure what i did wrong. help was asked for, so i supplied it! i don't see the problem with that. as long as Heidi studies the code and knows what and how i did it, i think that's enough. sometimes just a quick start on (in this case, arrays) a subject is all a programmer needs.

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Smile programming

    Stallion...
    Thank you again for getting me on the right track. Hopefully, I will ace my test over arrays.....I appreciate your time and help. We went over the material for the test this morning in class. I am new to programming so all help is appreciated. I don't really understand why a few people got "upset" with you helping me. Well, take care.
    heidi

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>I don't really understand why a few people got "upset" with you helping me.
    Because often providing real/complete code as answer is not the way to help the newbie learn. Yes, you might get to see how it should be done, but you've missed the thought process that went into designing the code, and that is one of the key things to understand.

    Anyway, stick around and learn some more....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    i guess i can see where you're coming from, but heidi sounded like she was actually out to learn and not let others do the homework.

    and even so, i don't see why quzah had to waste a post on just saying something like that. that really wasn't necessary. if he didn't agree, he didn't have to help, but he could've kept his mouth shut.

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by stallion
    and even so, i don't see why quzah had to waste a post on just saying something like that. that really wasn't necessary. if he didn't agree, he didn't have to help, but he could've kept his mouth shut.
    I could have kept my mouth shut, and this problem would continue and continue for all of time. Burying my head in the sand doesn't solve problems (unless I'm trying not to hear, or am trying to see what it's like to breathe sand).

    If you had actually read the rules of the forum, you'd know why I posted. Obviously you didn't, which is why I posted. Perhaps you should, instead of trying to justify yourself, actually read the forum rules. While you're at it, read the FAQ.

    It'll do you and the other posters some good.

    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Smile reply to Hammer

    Hi Hammer....
    I do hope to learn from belonging to this board and I will stick around. I feel a little "stupid" ;and I hope I did not offend anyone. I realize that I can learn so much from most of you experienced programmmers.
    So, it is not "proper message board etiquette" to post others "answers" (code), right? (or ask for "answers"/help) Take care.

  13. #13
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    stallion,

    it's right to teach ppl about programming,
    but, you may give some example, and then leave this question to them to try by their ownself. wanna to know my friends 's story ,Heidi?

    well, my friend did very poor in C programming, and he always wish for answer from me. i just tell him, " why not you try by your own, i can teach you, but not giving this answer of the question to you. i give you some example, ..... try to take some few times doing your programming in your computer, not reading the C programming book...

    ya' know ? what's the conclusion anyway, my friend's programming did improve a lot, he may do his homework very well.

    so, heidi, i just wan to give some advise / comment try to do any programming by using computer. not reading. reading can't improve a lot. well, good luck, heidi...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM