Solved

# 5x3 array

Posted on 2006-06-17
331 Views
write a program segement to display the sum of the values in each row of a 5x3 type double array named table. How many row sums will be displayed? How many elements are included in each sum?

I do not know how to do 5x3 array.  We are suppose to learn this chapter on our own, it's not sticking... :(  thanks for your help.
0
Question by:thunderrolls
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 14

Expert Comment

ID: 16927545
you can create a 5x3 array this way

double myArray[5][3];

Now try to start on your own. When you're stuck, post the code here. Here are some usefull hints: http:Q_21676313.html
0

LVL 10

Accepted Solution

Khanh Doan earned 125 total points
ID: 16929160
I forgot posting full code to homeword question is not allow. Sorry.

5x3 array is like this :
a b c
d e f
1 9 7
4 5 6
g h j

You will use Nested loop FOR

for (i = 0; i < 5; i++) // use for each collumn
{
for (j = 0; j < 3; j++) //use for each row
{
sum += table[i][j]; //it like sum = sum + table[i][j];
}
}

the nested FOR will caculate all value in your array. To caculate value of each row, you use one dimension array[5]
so, the nested for wil be

for (i = 0; i < 5; i++) // use for each collumn
{
sum[i] = 0; // assign value of each row to zero
for (j = 0; j < 3; j++) //use for each row
{
sum[i] += table[i][j]; //it like sum = sum[i] + table[i][j];
}
}

to print value of each row, you use another for
for (i = 0; i < 5; i++)
printf("Sum of row %d : %d", i + 1, sum[i]);

Goodluck.
Bonmat86.
0

Author Comment

ID: 16930655

for(i=0; i < 5; i++)  {
sumr = 0;
for (j = 0; j < 3; j++) {
sumr += table[i][j];
}
printf("%d  %d\n", i, sumr);
}
0

LVL 14

Expert Comment

ID: 16930663

Looks good to me, but have you tried it?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
###### Suggested Courses
Course of the Month5 days, 13 hours left to enroll