# Multiplication table

Page 1 of 1

## 12 Replies - 10922 Views - Last Post: 11 January 2011 - 01:14 PMRate 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=209197&amp;s=eb19999bf597e06ff0e91e3113acd7cd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 thesamy

Reputation: 1
• Posts: 54
• Joined: 12-July 10

# Multiplication table

Posted 10 January 2011 - 07:58 AM

hi guys i have a problem i need to solve that i have been working on serveral of hours and i just cant solve it..

i did a Multiplication table with 2 loops and a Console.Write();
and it work fine.

but now i need to do it only with Console.WriteLine();
and i just cant find a way to do it.

can somone help me "get there"
without showing me any code so my stupid brain will get it?

p.s
sorry for my english

Is This A Good Question/Topic? 0

## Replies To: Multiplication table

### #2 Curtis Rutland

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

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

## Re: Multiplication table

Posted 10 January 2011 - 08:04 AM

You're saying you need to print out a multiplication table without loops? Start writing each individual 1 x 1, 1 x 2, 1 x 3, etc...because you need loops to do this right.

### #3 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6528
• Posts: 14,435
• Joined: 02-June 10

## Re: Multiplication table

Posted 10 January 2011 - 08:11 AM

insertAlias is right. You can't do it with *just* console.WriteLine().
Go back to the homework instructions and read them again.
If that doesn't help, go to the teacher who assigned this and get a better explanation of the assignment.

### #4 thesamy

Reputation: 1
• Posts: 54
• Joined: 12-July 10

## Re: Multiplication table

Posted 10 January 2011 - 08:16 AM

oops i didnt explain my self good.

i can use loops
but i cant use the command
Console.Write();

and
i can do any thing i want like using string and stuff

### #5 Curtis Rutland

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

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

## Re: Multiplication table

Posted 10 January 2011 - 08:18 AM

So this is a school project then?

Use a StringBuilder to create a buffer for each line. Then when you're done with the line, print the whole thing. Alternatively, you can just use a string and keep adding to it, but that's less efficient.

### #6 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6528
• Posts: 14,435
• Joined: 02-June 10

## Re: Multiplication table

Posted 10 January 2011 - 08:23 AM

insertAlias, on 10 January 2011 - 07:18 AM, said:

So this is a school project then?

Use a StringBuilder to create a buffer for each line. Then when you're done with the line, print the whole thing. Alternatively, you can just use a string and keep adding to it, but that's less efficient.

Quote

but i cant use the command Console.Write();

Buffering it isn't going to matter if the OP can't use Console.Write() to output the results.
What's the alternative?

### #7 thesamy

Reputation: 1
• Posts: 54
• Joined: 12-July 10

## Re: Multiplication table

Posted 10 January 2011 - 08:23 AM

i still dont know about buffer and string builders

can u expline me the
use string and keep addint to it part?
(without showing me the answer to my specific problem)
becuse i want to understand to way and apply it by my self.

### #8 Curtis Rutland

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

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

## Re: Multiplication table

Posted 10 January 2011 - 08:26 AM

tlhIn, on 10 January 2011 - 08:23 AM, said:

insertAlias, on 10 January 2011 - 07:18 AM, said:

So this is a school project then?

Use a StringBuilder to create a buffer for each line. Then when you're done with the line, print the whole thing. Alternatively, you can just use a string and keep adding to it, but that's less efficient.

Quote

but i cant use the command Console.Write();

Buffering it isn't going to matter if the OP can't use Console.Write() to output the results.
What's the alternative?

According to the initial post, he can use Console.WriteLine. I assume the lesson is in buffering values and outputting them all at once.

@thesamy
The general idea is that inside the loop where you normally would do your Console.Writes, you create an empty string as a buffer. Then every place you would have Console.Write(someString), you instead add what you would have outputted to the buffer (use the += operator). Then, at the point where you're ready to go to the next line, you Console.WriteLine the entire buffer.

This post has been edited by insertAlias: 10 January 2011 - 08:27 AM

### #9 thesamy

Reputation: 1
• Posts: 54
• Joined: 12-July 10

## Re: Multiplication table

Posted 10 January 2011 - 08:36 AM

thank u i think i get it
i will post qustion about it if i get in trouble agian

agian thank u both for fast reply!

### #10 thesamy

Reputation: 1
• Posts: 54
• Joined: 12-July 10

## Re: Multiplication table

Posted 11 January 2011 - 09:33 AM

got another problem that i need somone to expline it to me

i need to make a program that write line of stars with the user input.
exmple.
user type in 3
he get
*
**
***

now at first i need to do it with 2 loops and i did and everything work fine
but now i need to do it with 1 loop but i got a problem that i dont know how to
like restrt the string i buffer afther i Console.WriteLine() it.

here is the code:
```namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the number of lines");

string stars = "*";

for (int i = 1 ; i <= line ; i++)
{
Console.WriteLine(stars);
stars += stars;

}

}
}
}
```

i just start to use the buffer in my last program so i realy not sure how to do it.
can somone expline it to me without show in the sulotion?

### #11 Curtis Rutland

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

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

## Re: Multiplication table

Posted 11 January 2011 - 09:40 AM

Your logic is only slightly wrong here. You don't want to reset the buffer, in this case. The best thing you can do is take a pen and paper, and write down everything that is happening. Draw a long box for your variable stars and a box for line and i.

Then trace your execution. Change the content of the boxes as you go. You should notice that you're adding stars to stars, in effect doubling the number of stars you put on each line rather than increasing them by one.

This post has been edited by insertAlias: 11 January 2011 - 09:41 AM

### #12 thesamy

Reputation: 1
• Posts: 54
• Joined: 12-July 10

## Re: Multiplication table

Posted 11 January 2011 - 09:48 AM

wow i get it now its working!
thank u!!

### #13 [email protected]

Reputation: 1003
• Posts: 975
• Joined: 30-September 10

## Re: Multiplication table

Posted 11 January 2011 - 01:14 PM

You can construct the triangle using only one line of code. You would use the constructor of the string class. Here is an example:

```Console.WriteLine(new String('*',5);

```

That would print 5 *'s. You can use the initalizer variable of the for loop ('i') in place of the 5 in the above code.

Think about it this way, your looping through each line in your for loop aren't you? So, on the first loop through, 'i' is 1 (representing line 1), on the second loop through, it's 2 (representing line 2) etc. The line number is equal to the number of stars you have to print (line 1 = 1 stars, line 2 = 2 stars.

Now, can you use the code above, in a for loop, to print out the triangle by replacing the 5 with i?

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }