Answer to Question #273682 in C# for Holik

Question #273682

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

1
Expert's answer
2021-12-02T14:16:41-0500
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();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS