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.
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
thunderrollsAuthor Commented:
how about this...does this work?
for(i=0; i < 5; i++) {
sumr = 0;
for (j = 0; j < 3; j++) {
sumr += table[i][j];
}
printf("%d %d\n", i, sumr);
}
In this whiteboard video, Professor Wool highlights the challenges, benefits and trade-offs of utilizing zero-touch automation for security policy change management. Watch and Learn!
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