multiplication table

Hiya all - I need help with multiplication tables in C#

Page 1 of 1

3 Replies - 3563 Views - Last Post: 25 April 2008 - 12:28 PM Rate Topic: -----

#1 priceaprice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 24-April 08

multiplication table

Posted 24 April 2008 - 12:17 AM

Hi all. I should joined in some time ago but I had a few other very big assignments and now I`ve returned to this to try and get past this.

I need to do a multiplication table: 15*15 using 2 for loops, one nested inside the other. The problem is I am a bit lost and confused.

for (int  accross = 1; accross < 13; accross = accross + 1)
			{
				if ((accross % 6) == 0)

				{ memo.AppendText("*"); }
				memo.AppendText(accross.ToString() + "\n");
				

				for (int down = 1; down < 13; down = down + 1)
				{
					if ((down % 6) == 0)

					{ memo.AppendText("*"); }
					memo.AppendText((accross * down).ToString() +"\t");




Any help and guidance appreciated.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: multiplication table

#2 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,476
  • Joined: 07-April 08

Re: multiplication table

Posted 25 April 2008 - 12:20 PM

also what errors are you getting??




i cant test it right as i only have access to VS 6.0 but try this:
for (int accross = 1; accross < 13; accross++)
	 for (int down = 1; down < 13; down++)
	  {
			  if ((accross % 6) == 0)

				{ memo.AppendText("*"); }
				memo.AppendText(accross.ToString() + "\n");
			 
				if ((down % 6) == 0)

					{ memo.AppendText("*"); }
					memo.AppendText((accross * down).ToString() +"\t");
		}


when i get to my dev box i'll check this code out more.

This post has been edited by rgfirefly24: 25 April 2008 - 12:21 PM

Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: multiplication table

Posted 25 April 2008 - 12:22 PM

Well you are certainly on the right track. Just a few minor adjustments like the range of your rows and columns and and you will have it. I am not sure why you are adding the asterisk in there, but you are doing it right if you want the asterisk to appear for every value that is a multiple of 6.

// Example for you
private void button1_Click(object sender, EventArgs e)
{
            // For each row from 1 to 15
            for (int down = 1; down <= 15; down++)
            {
                // Loop across from 1 to 15
                for (int across = 1; across <= 15; across++)
                {
                    // Appending the multiplication of the row and the column (adding a space for formatting)
                    memo.AppendText((across * down).ToString() + " ");
                }

                // At the end of each row, add a carriage return line feed
                memo.AppendText("\r\n");
            }
}



The above example will then print the multiplication chart in the memo textbox. Enjoy!

"At DIC we be multiplication table mastering code ninjas... DIC = Me * 80000 members" :snap:
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: multiplication table

Posted 25 April 2008 - 12:28 PM

Topic renamed to be more descriptive.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1