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