Write a C# program that display multiplication tables. The program lets the user
ID: 3723412 • Letter: W
Question
Write a C# program that display multiplication tables.
The program lets the user input a number from a text box, then the user clicks "Show" button, then the multiplication table of the input number will be printed out, from 1 to 9, line by line in a output label. A check box called "Reverse" will be provided. If the check box is checked, the the multiplication table will be printed in reverse order (from 9 to 1). You MUST use "for loop" to create multiplication table.
Example: If the user input 3 and Reverse check box is/isn't checked, then the final result will be displayed as follows:
Not checked
Checked
3 x 1 = 3
3 x 9 = 27
3 x 2 = 6
3 x 8 = 24
3 x 3 = 9
3 x 7 = 21
3 x 4 = 12
3 x 6 = 18
3 x 5 = 15
3 x 5 = 15
3 x 6 = 18
3 x 4 = 12
3 x 7 = 21
3 x 3 = 9
3 x 8 = 24
3 x 2 = 6
3 x 9 = 27
3 x 1 = 3
Not checked
Checked
3 x 1 = 3
3 x 9 = 27
3 x 2 = 6
3 x 8 = 24
3 x 3 = 9
3 x 7 = 21
3 x 4 = 12
3 x 6 = 18
3 x 5 = 15
3 x 5 = 15
3 x 6 = 18
3 x 4 = 12
3 x 7 = 21
3 x 3 = 9
3 x 8 = 24
3 x 2 = 6
3 x 9 = 27
3 x 1 = 3
Explanation / Answer
/*
* C# Program to Find and display the Multiplication Table
*/
using System;
class Multipication
{
static void Main()
{
int no;
Console.Write("Enter a no : ");
no = Convert.ToInt32(Console.ReadLine());
while (no <= 0)
{
Console.WriteLine("You entered an invalid no");
Console.Write("Enter a no great than 0: ");
no = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Multiplication Table :");
for (int i = 1; i <= no; i++)
{
Console.WriteLine(" ");
for (int j = 1; j <= no; j++)
{
Console.Write("{0,6}", i * j);
}
}
Console.Read();
}
}
Output
Here is the output of the C# Program:
Enter a No : 5
Multiplication Table :
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.