Wednesday 3 January 2018

Multiplication Table Program in C#(Sharp)

               Multiplication Table Program in C#(Sharp)

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

namespace multiplication_table
{
    // multiplication table//
    class Program
    {
        static void Main(string[] args)
        {
            int i, table; // define integer variable
            string Str = args[0]; // get input from commandline and store this value in str variable
            double Num;   // define double value 
            bool isNum = double.TryParse(Str, out Num); // converting string to int if a conversion succeeded then store isNum is true otherwise false
            if (isNum) // if isNum value is true then conversion succeeded 
            {
                table = Convert.ToInt32(args[0]); // convert string value to integer 
                Console.WriteLine("Multiplication table of "+table);
                for (i = 1; i <= 10; i++) // using for loop for table(1...10)
                {
                    int result = table * i; // multiplication with commandline argument and i 
                    Console.WriteLine("{0} X {1} = {2}", table, i, result); // using placeholder to print table,i value and result

                }
                Console.ReadLine();
            }
            else   // if isNum value is false then conversion failed
            {
                Console.WriteLine("Invalid number");
                

            }

        }
    }
}

No comments:

Post a Comment

😍Developer on Weekends #shorts #officememes #developermemes

😍Developer on Weekends #shorts #officememes #developermemes Welcome to the latest viral YouTube shorts meme for developers! 😍Developer on...