Several Multiplication Tables, (Use Do While) - C# Programming Exercise

This C# exercise aims to create a program that displays multiplication tables from 2 to 6 using nested do...while loops. A do...while loop executes a block of code at least once, then repeats the execution as long as the condition is true. Using nested loops in this case allows us to create a multiplication table for multiple numbers at once. In this program, the first do...while loop will iterate through the numbers 2 to 6, and the second do...while loop will show the multiplications for each number in the corresponding table. The output format will include the multiplication of each number by values from 1 to 10. This type of structure is useful for creating mathematical tables, especially when multiple results need to be displayed in an organized and repetitive manner within the same cycle.

 Category

Flow Control

 Exercise

Several Multiplication Tables, (Use Do While)

 Objective

Write a C# program that display multiplication tables from 2 to 6 using nested "do...while" loops.

 Write Your C# Exercise

using System; // Importing the System namespace to use Console functionalities

class Program
{
    // Main method where the program execution begins
    static void Main()
    {
        int i = 2; // Variable to iterate through numbers 2 to 6
        int j; // Variable for the multiplication factor (1 to 10)

        // Outer do...while loop for the numbers 2 to 6
        do
        {
            j = 1; // Resetting the multiplication factor for each table

            // Printing the multiplication table for the current number (i)
            Console.WriteLine($"Multiplication Table for {i}:");

            // Inner do...while loop for multiplying the current number (i) by 1 to 10
            do
            {
                // Displaying the current multiplication result
                Console.WriteLine($"{i} x {j} = {i * j}");
                j++; // Incrementing the multiplication factor
            }
            while (j <= 10); // Continue until multiplication factor is 10

            Console.WriteLine(); // Adding a blank line for separation between tables

            i++; // Incrementing the number for the next multiplication table
        }
        while (i <= 6); // Continue until the number reaches 6
    }
}

 Share this C# exercise

 More C# Programming Exercises of Flow Control

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  Square

    This C# exercise aims to create a program that prompts the user to enter a number and a width, then displays a square with the given width, using...

  •  Break & continue

    This C# exercise aims to develop a program that displays the even numbers from 10 to 20, both inclusive, except for 16, using three different approaches...

  •  Rectangle V2

    This C# exercise aims to develop a program that asks the user for a number, a width, and a height, and then displays a rectangle with the provide...

  •  Repetitive structures

    This C# exercise aims to develop a program that prompts the user for two numbers and displays all the numbers between them (inclusive) three times using for, while...

  •  Digits in a number

    This C# exercise aims to teach how to develop a program that calculates the number of digits in a positive integer. The program uses an efficient technique by perform...

  •  Hollow square

    This C# exercise aims to develop a program that asks the user for a symbol and a width, and then displays a hollow square of that width using the provid...