The Program in C# Program to Print any input Multiplication table is given below:
using System;
namespace MultiplicationTable
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family, Enter the number here to find their multiplication table: ");
int num = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Okay, the multiplication table of " + num + ":");
for (int i = 1; i <= 10; i++)
{
Console.WriteLine(num + " x " + i + " = " + (num * i));
}
Console.ReadLine();
}
}
}
Output:
Hello Codeauri Family, Enter the number here to find their multiplication table:
10
Okay, the multiplication table of 10:
10 x 1 = 10
10 x 2 = 20
10 x 3 = 30
10 x 4 = 40
10 x 5 = 50
10 x 6 = 60
10 x 7 = 70
10 x 8 = 80
10 x 9 = 90
10 x 10 = 100
Pro-Tips💡
Here are the step-by-step execution of above program:
using System;
is a directive that imports theSystem
namespace, which contains various classes and methods used in the program.namespace MultiplicationTable
defines a namespace that contains all the classes and methods within it.class Program
defines a class that contains the program’s logic.static void Main(string[] args)
is the program’s entry point, which is executed when the program starts.Console.WriteLine("Hello Codeauri Family, Enter the number here to find their multiplication table: ");
prints a prompt asking the user to enter a number.int num = Convert.ToInt32(Console.ReadLine());
reads the user’s input, converts it from a string to an integer usingConvert.ToInt32
, and stores the result in the variablenum
.Console.WriteLine("Okay, the multiplication table of " + num + ":");
prints a message indicating the number for which the multiplication table will be displayed.for (int i = 1; i <= 10; i++)
is a for loop that will iterate 10 times.i
is the loop variable that starts from 1 and increments by 1 each time through the loop.Console.WriteLine(num + " x " + i + " = " + (num * i));
calculates the product ofnum
andi
and prints the result. The line concatenates strings and the product to produce the output.Console.ReadLine();
waits for the user to press the Enter key before ending the program
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.