Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 28, 2025 14:19
Show Gist options
  • Save Strelok78/5fae8f4edd04cec681076f691407575a to your computer and use it in GitHub Desktop.
Save Strelok78/5fae8f4edd04cec681076f691407575a to your computer and use it in GitHub Desktop.
get first line multiple and sum second line in two dimensional array of int
using System;
namespace iJuniorPractice
{
class Program
{
static void Main(string[] args)
{
int[,] numbers =
{
{ 2, 3, 4 },
{ 5, 6, 7 },
{ 10, 1, 9 }
};
int multipleColumnIndex = 0;
int sumRowIndex = 1;
int multiple = 1;
int sum = 0;
int dimensionRowLength = numbers.GetLength(0);
int dimensionColumnLength = numbers.GetLength(1);
for (int i = 0; i < dimensionRowLength; i++)
{
multiple *= numbers[i, multipleColumnIndex];
}
for (int i = 0; i < dimensionColumnLength; i++)
{
sum += numbers[sumRowIndex, i];
}
Console.WriteLine("Array elements:");
for (int i = 0; i < dimensionColumnLength * dimensionRowLength; i++)
{
Console.Write(numbers[i / dimensionColumnLength, i % dimensionColumnLength] + " ");
if ((i + 1) % dimensionColumnLength == 0)
Console.WriteLine();
}
Console.WriteLine($"Multiple of {multipleColumnIndex + 1} column = {multiple}");
Console.WriteLine($"Sum of {sumRowIndex + 1} row = {sum}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment