Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Location
    Portland, OR
    Posts
    4

    Need Help Coding a C Program - Please Help

    Hello Everyone,
    I was wondering If anyone can help me with a homework assignment in C programming.

    My Assignment:

    Write a program called matrix.c that reads in an array of 3x4 integers and then displays the array and prints the row sums (totals). Output would look as shown below (based on the input by the user of course) - program output is in bold, user data is regular - the bold text is for clarification only, you are not expected to display text in bold . Program matrix.c should use a function to compute and display row totals sumrow(). The sumrow function would accept the array as an argument, and return nothing (output display is internal to the function). You might also consider using a function to read in the user's input, as well as another function to display/print the contents of your array as well. The function sumrow is the only function required for this exercise, any others would simply be an opportunity to gain further experience working with function.
    Warning: Avoid "hard coding" any array element data in your program. The code should be nearly identical for a 3x4 matrix as it would be for a 100x200 matrix.

    Please enter data for a 3 by 4 array:
    2 3 4 0
    1 9 2 2
    4 1 0 1

    If you can help me please contact me via aim or msn.

    Aim: exanzix
    yahoo: trailblazin05

    I will apperciate any help thank you for your time.

  2. #2
    Ummm.

    If you don't figure out how to do this one on your own, how are you going to keep up with the rest of the semester?

  3. #3
    Join Date
    Jun 2004
    Location
    Bay Area -USA
    Posts
    1,740
    "Avoid "hard coding" any array element data in your program. The code should be nearly identical for a 3x4 matrix as it would be for a 100x200 matrix."

    probably saying... use a for loop

    have fun! :-D
    <<< Please see Forum Guidelines for signature setup. >>>

  4. #4
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    1,097
    Originally posted by VolkNet
    "Avoid "hard coding" any array element data in your program. The code should be nearly identical for a 3x4 matrix as it would be for a 100x200 matrix."

    probably saying... use a for loop

    have fun! :-D
    That and saying use #defines or constants instead of magic numbers in said for loop. Or even accepting user input or infering the size of the matrix from the input...

    But agreed, this is pretty darn trivial. Store the data in a linear array. The first n elements are row 1, the next n are row 2. You'll need an outer loop that skips by n, and an inner loop to iterate within that row and generate the sum.

    The rest I will leave to you to figure out. If you can't, I second dzeanah's question. Learn the stuff, don't just expect other people to do all the work and learn nothing...why are you paying for the course in that case...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •