Multiplication Tables

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1706 Views - Last Post: 04 October 2012 - 07:32 AM Rate Topic: -----

#16 ankit.mca.aaidu  Icon User is offline

  • New D.I.C Head

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

Re: Multiplication Tables

Posted 02 October 2012 - 02:12 AM

Hello sir i have done it, it is working now
int i,j,sum=0;            
            for (i = 1; i <= 10; i++)
            {
                for (j = 1; j <= 12; j++)
                {
                    sum = i * j;
                    if (j == 1)
                    {
                        Console.Write("{0,2}", sum);
                    }
                    else
                    {
                        Console.Write("{0,4}", sum);
                    }                   
                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }


This post has been edited by Curtis Rutland: 02 October 2012 - 07:28 AM
Reason for edit:: stop quoting things!

Was This Post Helpful? 0
  • +
  • -

#17 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 396
  • Joined: 04-January 11

Re: Multiplication Tables

Posted 02 October 2012 - 06:24 PM

View Postankit.mca.aaidu, on 02 October 2012 - 12:03 AM, said:

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

No, you do not need a 2D array for printing things to the console. Read the link that rfs02 posted, then read this page:

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


The tutorial is great and really easy to understand. What part is it that you don't understand and having a hard time to implement? Tell us what exactly so we could help.

Anyway, this is the first time I heard of that alignment in String.Format so I am really impressed and gave the post a plus.

I changed the \t idea into it so here's my revised code.

            int intProduct = 0;
            for (int intRow = 1; intRow <= 12; intRow++)
            {
                for (int intColumn = 1; intColumn <= 12; intColumn++)
                {
                    intProduct = intRow * intColumn;
                    Console.Write(String.Format("{0,-5:##}", intProduct));
                }
                Console.WriteLine();
            }
            Console.ReadLine();


This post has been edited by November-06: 02 October 2012 - 06:34 PM

Was This Post Helpful? 1
  • +
  • -

#18 ankit.mca.aaidu  Icon User is offline

  • New D.I.C Head

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

Re: Multiplication Tables

Posted 04 October 2012 - 04:08 AM

View PostNovember-06, on 02 October 2012 - 06:24 PM, said:

View Postankit.mca.aaidu, on 02 October 2012 - 12:03 AM, said:

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

No, you do not need a 2D array for printing things to the console. Read the link that rfs02 posted, then read this page:

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



The tutorial is great and really easy to understand. What part is it that you don't understand and having a hard time to implement? Tell us what exactly so we could help.

Anyway, this is the first time I heard of that alignment in String.Format so I am really impressed and gave the post a plus.

I changed the \t idea into it so here's my revised code.

            int intProduct = 0;
            for (int intRow = 1; intRow <= 12; intRow++)
            {
                for (int intColumn = 1; intColumn <= 12; intColumn++)
                {
                    intProduct = intRow * intColumn;
                    Console.Write(String.Format("{0,-5:##}", intProduct));
                }
                Console.WriteLine();
            }
            Console.ReadLine();


hello sir thanks for your answer... please tell me what this code is doing
"{0,-5:##}"
i am not getting this can you please explain
Was This Post Helpful? -3
  • +
  • -

#19 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Multiplication Tables

Posted 04 October 2012 - 04:27 AM

View Postankit.mca.aaidu, on 04 October 2012 - 04:38 PM, said:

hello sir thanks for your answer... please tell me what this code is doing
"{0,-5:##}"
i am not getting this can you please explain


Those are formatting strings in C#. Here, they are used for alignment to the extreme left.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#20 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3616
  • View blog
  • Posts: 11,263
  • Joined: 05-May 12

Re: Multiplication Tables

Posted 04 October 2012 - 07:03 AM

View Postankit.mca.aaidu, on 04 October 2012 - 04:08 AM, said:

hello sir thanks for your answer... please tell me what this code is doing
"{0,-5:##}"
i am not getting this can you please explain


The fact that you are asking about this is a pretty good indication that you have not been reading any of the links multiple people have been sending you about formatting strings.

This post has been edited by Skydiver: 04 October 2012 - 07:03 AM

Was This Post Helpful? 3
  • +
  • -

#21 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4525
  • View blog
  • Posts: 7,893
  • Joined: 08-June 10

Re: Multiplication Tables

Posted 04 October 2012 - 07:32 AM

And on that note, I'm closing this thread. If you're not willing to take our advice, then you just want people to hand you code. We don't do that here.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2