Friday, November 9, 2018

C# program to print multiplication table

এই program দিয়ে যেকোনো সংখ্যার নামতা(multiplication) যেকোনো সংখ্যা পর্যন্ত print করানো যায় -


using System;
using System.Collections.Generic;
using System.Linq;

namespace MainPrograms
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // Prompt the user to enter a number for the multiplication table
            Console.WriteLine("For which number do you want to print multiplication table");


            // Read the number from console and convert to integer
            int Number = Convert.ToInt32(Console.ReadLine());


            // Prompt the user for multiplication table target
            Console.WriteLine("What is your target? 10,20,30 etc...");


            // Read the target from console and convert to integer
            int Target = Convert.ToInt32(Console.ReadLine());


            // Loop to print multiplication table until we reach the target
            for (int i = 1; i <= Target; i++)
            {
                // Compute multiplication result
                int Result = Number * i;


                // Format and Print the multiplication table
                Console.WriteLine(Number.ToString()+"X"+i.ToString()+"="
                                                                                                 +Result.ToString());
            }

            // The above line can also be rewritten as shown below.
            // Console.WriteLine("{0} X {1} = {2}", Number, i, Result);
            Console.ReadLine();
        }
    }
}


No comments:

Post a Comment