Question #273682

13. Find the product of the negative elements of the string K of any two-dimensional array.

Expert's answer

using System;
using System.Collections.Generic;


namespace App
{
    class Program
    {
        public static void Main()
        {
            Console.Write("Enter size of the two-dimensional array: ");
            int size = int.Parse(Console.ReadLine());
            int[,] squareArray = new int[size, size];
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    Console.Write("Enter element[{0}][{1}]: ", i, j);
                    squareArray[i, j] = int.Parse(Console.ReadLine());
                }
            }
            int product = 1;
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (squareArray[i, j] < 0) {
                        product *= squareArray[i, j];
                    }
                }
            }
            Console.WriteLine("The product of the negative elements : {0}", product);
            Console.ReadLine();
        }
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS