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
C# Exercise Example
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
}
}
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#.
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...
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...
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...
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...
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...
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...