Solved

5x3 array

Posted on 2006-06-17
5
326 Views
Last Modified: 2012-06-21
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
Comment
Question by:thunderrolls
  • 2
5 Comments
 
LVL 14

Expert Comment

by:cwwkie
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

by:
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

by:thunderrolls
ID: 16930655
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);
}
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16930663
> how about this...does this work?

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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I recover data from my iphone 3g 4 61
How do I test for current date? 9 102
Why this code doesn't work? 8 99
Problem with MFCApp 78 379
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now