Coding Lab - TechOnTechnology

Program in C# to find the sum and product of numbers entered as command line parameters

using System;

namespace Lab_Ex_2
{
    class commandLineParameters
    {
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("\n This program finds the SUM & PRODUCT of two numbers entered as command line parameters.");
                Console.WriteLine("\n So Please enter two numbers as command line parameters.");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("\n This program finds the SUM & PRODUCT of two numbers entered as command line parameters.");
                Console.WriteLine("\n Command line parameters recieved are: ");
                foreach (string str in args)
                Console.WriteLine(str);
                int sum = 0, prod = 1, data;
                foreach (string str in args)
                {
                    data = int.Parse(str);
                    sum = sum + data;
                    prod = prod * data;
                }
                Console.WriteLine(" \n Sum of command line parameters = " + sum);
                Console.WriteLine(" \n Product of command line parameters = " + prod);
                Console.ReadLine();
            }
        }
    }
}


Name

Email *

Message *