Multiplication Table (Use While) - C# Programming Exercise

In this C# exercise, you will learn how to write a program that asks the user to enter a number and then displays its multiplication table using a while loop. The while loop is a control structure that repeatedly executes a block of code as long as a specific condition is true. In this case, the program will multiply the number entered by the user from 1 to 10 and display each result on the screen. This exercise is perfect for learning how to work with loops in C# and perform repetitive calculations without having to write multiple lines of code. By using the while loop, you can efficiently display a series of repeated operations, such as multiplication tables. This type of exercise is ideal for beginners who want to improve their understanding of loops and control structures in C#.

The while loop will allow you to iterate through the multiplications without writing redundant code, enhancing the readability and efficiency of the program. This is an excellent starting point for diving deeper into loop management in C# and understanding how to control program execution based on a condition.

 Category

Flow Control

 Exercise

Multiplication Table (Use While)

 Objective

Write a C# program that prompts the user to enter a number and displays its multiplication table using a 'while' loop.

 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 number; // Declaring a variable to store the number entered by the user
        int counter = 1; // Declaring and initializing the counter variable to 1

        // Asking the user to enter a number for the multiplication table
        Console.Write("Please enter a number: ");
        number = Convert.ToInt32(Console.ReadLine()); // Converting the input to an integer

        // Displaying the multiplication table using a while loop
        Console.WriteLine("The multiplication table for {0} is:", number); // Printing the header for the table

        // Using a while loop to display the multiplication table from 1 to 10
        while (counter <= 10) // The loop continues as long as the counter is less than or equal to 10
        {
            // Printing the result of the multiplication
            Console.WriteLine("{0} x {1} = {2}", number, counter, number * counter); // Printing the current multiplication result

            counter++; // Incrementing the counter by 1 after each iteration
        }
    }
}

 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#.

  •  Odd numbers descending

    In this C# exercise, you will learn how to write a program that displays the odd numbers from 15 down to 7 using a while loop. The while loop is a control stru...

  •  Sum numbers

    In this C# exercise, you will learn how to write a program that asks the user to enter an undetermined amount of numbers (until 0 is entered) and displays the total sum of t...

  •  Two negative numbers

    In this C# exercise, you will learn how to write a program that prompts the user to enter two numbers and determines whether both numbers are negative or not. This type of p...

  •  One or two negative numbers

    In this C# exercise, you will learn how to write a program that prompts the user to enter two numbers and then determines whether both numbers are negative, only one is nega...

  •  Multiples

    In this exercise, you will learn how to use the modulo operator % to find numbers between 1 and 500 that are divisible by both 3 and 5. The program will...

  •  Number repeated

    This exercise teaches you how to display a number repeated a number of times specified by the user. Three loop structures will be used to perform the repetition: while, d...