April 22, 2020

How to write a program in C# to print a table in for loop.

Write a program in C Sharp to print a table in for loop.
How to write a program in C# to print a table in for loop.

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 num, i, result;
            Console.Write("Enter table number\t");
            num = Convert.ToInt32(Console.ReadLine());

            for (i = 1; i <= 10; i++)
            {
              result = num * i;
              Console.WriteLine("{0} x {1} = {2}", num, i, result);
            }

            Console.ReadLine();
        }
    }
}

                                                             Sample Output


How to write a program in C# to print a table in for loop.

If you want to display table of  4 just enter 4 after that you get table of 4.
Whatever table you want just enter number and get table






No comments:

Post a Comment