Exercise
Several multiplication tables, (use do while)
Objetive
Write a C# program that display multiplication tables from 2 to 6 using nested "do...while" loops.
Example Code
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
}
}