# The Sum Of The Columns In Multiplication Table

Page 1 of 1

## 6 Replies - 10106 Views - Last Post: 30 September 2012 - 06:52 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=293694&amp;s=b5ab17666539076f2d30331a0cd7201e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Kilanz

Reputation: 0
• Posts: 6
• Joined: 29-September 12

# The Sum Of The Columns In Multiplication Table

Posted 30 September 2012 - 01:58 AM

How Can I Add The Numbers In The Columns Of The Multiplication Table ?

For Example

1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16
10 20 30 40 = Total

import java.awt.*;
import java.util.*;
import java.io.*;

public class MultiplicationTable{
public static void main(String[] args) throws IOException
{

int[][] multtable = new int[11][11];

System.out.print( "Enter your number: " );

int n = Integer.parseInt( input );

System.out.print("*");
for (int a = 1; a <= n; a++) {
System.out.print("\t" + a);
}
System.out.println(" ");
for (int i = 0; i <= n; i++) {

for (int j = 0; j <= n; j++) {

multtable[i][j] = i * j;
}
}
System.out.print("\t");
System.out.print("-----------------------------------------------------------------------------");
System.out.println("");

for (int i = 1; i <= n; i++) {

System.out.print(i + "|");

for (int j = 1; j <= n; j++)

{
System.out.print("\t" + multtable[i][j]);
}
System.out.println("");
System.out.println("");
}
}
}

This post has been edited by baavgai: 30 September 2012 - 03:03 AM
Reason for edit:: moved and tagged, java ain't python

Is This A Good Question/Topic? 0

## Replies To: The Sum Of The Columns In Multiplication Table

### #2 Larry71

Reputation: 3
• Posts: 44
• Joined: 05-June 12

## Re: The Sum Of The Columns In Multiplication Table

Posted 30 September 2012 - 03:21 AM

I don't know why,but your post was split in two and my answer that I gave was disappeared.

As I told before,the sum of n numbers is n*(n+1)/2.For example the sum from 1 to 10 is 10*11/2=55.
So the 10,20,30,40 you are writing in the example,are rows*(rows+1)/2 in a loop where you use the number of the cols and multiply each time with.

If not wrong.

### #3 Kilanz

Reputation: 0
• Posts: 6
• Joined: 29-September 12

## Re: The Sum Of The Columns In Multiplication Table

Posted 30 September 2012 - 03:52 AM

I Dont Know How To Debug It I Tried Many Times But Still So Many Errors. I Can't Make The Code Add The Numbers Inside The Cols.

### #4 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: The Sum Of The Columns In Multiplication Table

Posted 30 September 2012 - 04:16 AM

If there are compiler errors you want help with, post them, copied and pasted just as they appear at your end. If there are logic errors that cause the program's results to be incorrect, describe the current results and the desired results, using actual or sample runs as available.

This is what I get when I run your program:
*	1	2	3	4	5
-----------------------------------------------------------------------------
1|	1	2	3	4	5

2|	2	4	6	8	10

3|	3	6	9	12	15

4|	4	8	12	16	20

5|	5	10	15	20	25

What should it be?

This post has been edited by GregBrannon: 30 September 2012 - 04:18 AM

### #5 Kilanz

Reputation: 0
• Posts: 6
• Joined: 29-September 12

## Re: The Sum Of The Columns In Multiplication Table

Posted 30 September 2012 - 05:25 AM

The Code Should Let the User Input How Many Rows And Columns. And When The Multiplication Table Isa Done. Then The Addition Will Take Place Like This:

* 1 2 3 4 5
-----------------------------------------------------------------------------
1| 1 2 3 4 5

2| 2 4 6 8 10

3| 3 6 9 12 15

4| 4 8 12 16 20

5| 5 10 15 20 25
15 30 45 60 75 This Row Is the Total Of the Following Columns

I Wish You'll Get It. Hehe

### #6 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: The Sum Of The Columns In Multiplication Table

Posted 30 September 2012 - 05:45 AM

Hehe, and I was hoping you'd get it.

The sum of each column could be calculated either by formulas (probably a pain) or by summing the values in each row of each column in nested for loops. You might use a new array, sumOfColumns[], that has as many members as their are columns, then use nested for loops to calculate:
for ( the number of columns )
{
for ( the number of rows )
{
sumOfColumns[column] += multTable[row][column];
}
}

Instead of creating an additional set of nested for loops to make this calculation, a goal should be to include it in the loops you already have.

### #7 Kilanz

Reputation: 0
• Posts: 6
• Joined: 29-September 12

## Re: The Sum Of The Columns In Multiplication Table

Posted 30 September 2012 - 06:52 AM

GregBrannon, on 30 September 2012 - 05:45 AM, said:

Hehe, and I was hoping you'd get it.

The sum of each column could be calculated either by formulas (probably a pain) or by summing the values in each row of each column in nested for loops. You might use a new array, sumOfColumns[], that has as many members as their are columns, then use nested for loops to calculate:
for ( the number of columns )
{
for ( the number of rows )
{
sumOfColumns[column] += multTable[row][column];
}
}

Instead of creating an additional set of nested for loops to make this calculation, a goal should be to include it in the loops you already have.

How Does Thje Code Go Sir ? I Got It But Where Should I Put The Code Snippet You Made. Sorry I'm a Noob Programmer (