I was wondering If anyone can help me with a homework assignment in C programming.
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.
I will apperciate any help thank you for your time.
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...