April 22, 2020

How to write a program in C# to print Multiplication table

Write a program in C Sharp to print Multiplication table.


How to write a program in C# to print Multiplication table

Sample Solution

C# Sharp Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Loop_Examples1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n1, n2;

 Console.Write("Enter table number upto which u want to generate : ");
            n1 = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= n1; i++)
            {
                Console.WriteLine("\n");

                for (int j = 1; j <= 10; j++)
                {
                    n2 = i * j;
                    Console.WriteLine("{0} * {1} = {2}", i, j, n2);

                }
                Console.ReadLine();
            }

        }
    }
}

                                                              Sample Output

How to write a program in C# to print Multiplication table

If you want to display table from 1 to 10 just enter 10 after that you get table from 1 to 10. You can get any range like 20,40,100  just enter number and get table.



No comments:

Post a Comment