Program to Generate Multiplication Table - (C# Basic Programs)
Generating a multiplication table is a common programming exercise that helps improve problem-solving skills. In this tutorial, we will discuss a program to generate a multiplication table using C# programming language.
Syntax
The syntax for generating a multiplication table is as follows:
for (int i = 1; i <= 10; i++) {
for (int j = 1 j <= 10; j++) {
int result = i * j;
Console.Write("{0} ", result);
}
Console.Write("\n"); // Add a newline after each row
}
Example
using System;
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10; j++) {
int result = i * j;
Console.Write("{0} ", result);
}
Console.Write("\n"); // Add a newline after each row
}
}
}
Output:
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
Explanation
This program uses a nested for loop structure to generate a multiplication table. The outer loop controls the rows of the table, while the inner loop controls the columns. The inner loop multiplies the current row and column values to calculate the product, and this value is printed to the console with a space delimiter.
Use
Generating a multiplication table program in C# is great for practicing problem-solving skills and improving coding abilities. They help programmers in developing a better understanding of loops, conditional statements, and how to manipulate variables and data structures.
Summary
In this tutorial, we have discussed a program to generate a multiplication table using C# programming language. We have seen the syntax, an example, explanation, and use of generating multiplication table programming in C#. By practicing these exercises, programmers can improve their problem-solving skills and become better equipped to tackle complex coding challenges.