# Multiplication Tables

• (2 Pages)
• 1
• 2

## 20 Replies - 3641 Views - Last Post: 04 October 2012 - 07:32 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=293734&amp;s=1124c6caf09fe39d1b10d24b1593a5b1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ankit.mca.aaidu

Reputation: -4
• Posts: 9
• Joined: 29-September 12

# Multiplication Tables

Posted 30 September 2012 - 11:33 AM

Print out the grade school multiplication table upto 12*12.

None
Print out the table in a matrix like fashion, each number formatted to a width of 4 (The numbers are right-aligned and strip out leadeing/trailing spaces on each line). The first 3 line will look like:
e.g.

```1   2   3   4   5   6   7   8   9  10  11  12
2   4   6   8  10  12  14  16  18  20  22  24
3   6   9  12  15  18  21  24  27  30  33  36

```

i am not able to print this column wise can you help please.....

```class Program
{
static void Main(string[] args)
{
int i,j,sum=0;
for (i = 1; i <= 12; i++)
{
for (j = 1; j <= 10; j++)
{
sum = i * j;
Console.WriteLine(sum);
}
}
}
}
```

this is my code....

This post has been edited by tlhIn`toq: 30 September 2012 - 12:35 PM
Reason for edit:: code tags added

Is This A Good Question/Topic? 0

## Replies To: Multiplication Tables

### #2 Skydiver

• Code herder

Reputation: 6111
• Posts: 21,035
• Joined: 05-May 12

## Re: Multiplication Tables

Posted 30 September 2012 - 12:19 PM

You need to take some time to dig through the MSDN documentation, and not just rely on Intellisense. You would have found this:
http://msdn.microsof...y/9xdyw6yk.aspx

### #3 November-06

• D.I.C Regular

Reputation: 53
• Posts: 482
• Joined: 04-January 11

## Re: Multiplication Tables

Posted 30 September 2012 - 06:11 PM

The problem with your code is you are only using WriteLine() causing the next number to be written on the next line (like the behavior of 'Enter' key).

I revised your code to the following:

```            int intProduct = 0;
for (int intRow = 1; intRow <= 12; intRow++)
{
for (int intColumn = 1; intColumn <= 12; intColumn++)
{
intProduct = intRow * intColumn;
Console.Write(intProduct + "\t");
}
Console.WriteLine();
}

```

Sum is for addition, so I changed it to 'Product' since this is a multiplication table. The "\t" is to add tab.

Hope this helps.

### #4 rfs02

Reputation: 26
• Posts: 70
• Joined: 30-September 12

## Re: Multiplication Tables

Posted 30 September 2012 - 09:04 PM

You might also want to look into the MSDN page on Composite Formatting.

Specifically, check how to align text, which is always handy when you want to print a table.

### #5 ankit.mca.aaidu

Reputation: -4
• Posts: 9
• Joined: 29-September 12

## Re: Multiplication Tables

Posted 01 October 2012 - 03:55 AM

November-06, on 30 September 2012 - 06:11 PM, said:

The problem with your code is you are only using WriteLine() causing the next number to be written on the next line (like the behavior of 'Enter' key).

I revised your code to the following:

```            int intProduct = 0;
for (int intRow = 1; intRow <= 12; intRow++)
{
for (int intColumn = 1; intColumn <= 12; intColumn++)
{
intProduct = intRow * intColumn;
Console.Write(intProduct + "\t");
}
Console.WriteLine();
}

```

Sum is for addition, so I changed it to 'Product' since this is a multiplication table. The "\t" is to add tab.

Hope this helps.

hello sir i am thankful for your answer but its not working i want to print tables from 1 to 12 column wise.... each table in each different column
can you have solution for this.
i think i should use 2d array for this it will work??

### #6 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5103
• Posts: 9,283
• Joined: 08-June 10

## Re: Multiplication Tables

Posted 01 October 2012 - 07:12 AM

http://blog.stevex.n...ting-in-csharp/

That's a super-handy reference for most commonly used string formatting needs. What you're looking for is called "padding". You want each column to take the same amount of space, even if the content inside is of a different size.

### #7 ankit.mca.aaidu

Reputation: -4
• Posts: 9
• Joined: 29-September 12

## Re: Multiplication Tables

Posted 01 October 2012 - 10:36 AM

Hello Sir i tried this and it is working can you please check this out

```int i,j,sum=0;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++)
{
sum = i * j;
Console.Write(sum+"\t");
}
Console.WriteLine();
}

```

### #8 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5103
• Posts: 9,283
• Joined: 08-June 10

## Re: Multiplication Tables

Posted 01 October 2012 - 11:31 AM

You didn't read the links, did you. They explain how to do what you want. We're not going to give you the answer, we're here to help you find it. Both links have the information you need.

### #9 rfs02

Reputation: 26
• Posts: 70
• Joined: 30-September 12

## Re: Multiplication Tables

Posted 01 October 2012 - 01:50 PM

ankit.mca.aaidu, on 01 October 2012 - 10:36 AM, said:

Hello Sir i tried this and it is working can you please check this out

```int i,j,sum=0;
for (i = 1; i <= 10; i++)
{
for (j = 1; j <= 10; j++)
{
sum = i * j;
Console.Write(sum+"\t");
}
Console.WriteLine();
}

```

What you submitted is printing the multiplication tables up to 10x10, your requirement is to go up to 12x12.

Look at your output carefully and look at what's working and what's not. Keep in mind that when printing to the console, once you print 80 characters, the output will overlap to the next line automatically.

### #10 Skydiver

• Code herder

Reputation: 6111
• Posts: 21,035
• Joined: 05-May 12

## Re: Multiplication Tables

Posted 01 October 2012 - 03:07 PM

rfs02, on 01 October 2012 - 01:50 PM, said:

Keep in mind that when printing to the console, once you print 80 characters, the output will overlap to the next line automatically.

Actually it depends on how you configure your console window. The default setting is 80x25 characters to emulate the old IBM/PC DOS screens, but you can actually set it up to be bigger or smaller. I set mine up to be 120x50 so the compile errors don't wrap around as much and I get to see more errors before they scroll away (forcing me to use the mouse to get back to them).

### #11 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5103
• Posts: 9,283
• Joined: 08-June 10

## Re: Multiplication Tables

Posted 01 October 2012 - 04:28 PM

Off topic, but do you use csc.exe to compile very often? Or are you talking about using that for other compilers, perhaps C++?

### #12 Skydiver

• Code herder

Reputation: 6111
• Posts: 21,035
• Joined: 05-May 12

## Re: Multiplication Tables

Posted 01 October 2012 - 05:32 PM

I create a .csproj, and let msbuild.exe invoke csc.exe for me. I also have the .csproj run xunit.exe to run my unit tests as part of my build. Having the wider and taller console is really useful when the unit tests fail unexpectedly I need to scroll back to see what happened.

### #13 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 5103
• Posts: 9,283
• Joined: 08-June 10

## Re: Multiplication Tables

Posted 01 October 2012 - 05:34 PM

Gotcha. We use TFS to handle our builds and unit tests, so we don't see console output, we get handy reports. Also, we use MSTEST. My boss likes to say "happiness is little green check marks".

### #14 Skydiver

• Code herder

Reputation: 6111
• Posts: 21,035
• Joined: 05-May 12

## Re: Multiplication Tables

Posted 01 October 2012 - 05:41 PM

Yup, I used to use MSTest as well, but I got fed up with the random hangs and crashes that VS2008 and VS2010 would experience. When I went to the console window + Visual SlickEdit, I only ever fire up VS2010 for debugging, or to look at some the code posted here at DIC. So far VS2012 have been really stable, so I may go back to using VS as my primary environment but the jury is still out.

### #15 ankit.mca.aaidu

Reputation: -4
• Posts: 9
• Joined: 29-September 12

## Re: Multiplication Tables

Posted 02 October 2012 - 12:03 AM

Curtis Rutland, on 01 October 2012 - 07:12 AM, said:

http://blog.stevex.n...ting-in-csharp/

That's a super-handy reference for most commonly used string formatting needs. What you're looking for is called "padding". You want each column to take the same amount of space, even if the content inside is of a different size.

Hello sir please help me with this question . I am just a beginner in this field i want to do thing and i read the tutorial i am not able to implement it, please if you can do some favor to me