Saturday, 3 February 2018

Use the do-while loops in nested form and produces the following output in C#
 Multiple Tables

  1     2     3

  2     4     6

  3     6     9

Solution :

First Way

public static void SampleMethod()

        {

            int i = 1;

            int k = 1;

            do

            {

                int j = 1;

                do

                {

                    Console.Write(j * k + " ");

                    j++;



                } while (j <= 3);

                Console.WriteLine();

                k++;

                i++;



            } while (i <= 3);

        }
Second Way :
public static void SampleMethod()
        {
            int k = 1;
            for (int i = 1; i <= 3; i++)
            {

                for (int j = 1; j <= 3; j++)
                {

                    Console.Write(j * k + " ");
                }
                Console.WriteLine();
                k++;
            }
        }

0 comments:

Post a Comment

Powered by Blogger.

Followers

Translate

Currency Converter

Exchange Rate

Featured post

Interpolation in angular 5

When we want to communicate from component class to template ,we can use interpolation which use the { { expression }} to render the bound...

Popular Posts

My Facebook Page