How to find and display the Multiplication Table in C#?


To display multiplication table, you need to set the numbers and format the output property. Let’s say you want to find the table of 4 from 1 to 10. For that, set a while loop first till 10.

while (a <= 10) {
}

Now format the output to get the result as shown below. Here, n is 4 i.e. table of 4.

Console.WriteLine(" {0} x {1} = {2} 
", n, a, n * a);

The above will give a formatted output −

4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
.
.
.

The following is the complete example −

Example

using System;
public class Demo {

   public static void Main() {
      int n = 4, a = 1;

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

Updated on: 22-Jun-2020

628 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements