Multiplication table (use while) Learn programming C#

Lesson:

Flow Control


Exercise:

Multiplication table (use while)


Objetive:

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


Code:

using System;
'Multiplication table
public class Exercise23
{
    public static void Main()
    {
        int num, multiplier = 1;

        Console.Write("Insert a number to multiply: ");
        num = Convert.ToInt32(Console.ReadLine());

        while (multiplier <= 10)
        {
            Console.WriteLine("{0} x {1} = {2}",
                num, multiplier, num * multiplier);
            multiplier++;
        }
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.