Рекурсивная функция поиска минимального элемента в двумерном массиве - C#
Формулировка задачи:
помогите пожалуйста написать рекурсивную функцию которая находит минимальный элемент в матрице (двумерном массиве)
задачка в C# WindowsFormsApplication
актуально
Решение задачи: «Рекурсивная функция поиска минимального элемента в двумерном массиве»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication36
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int[,] arr = new int[3, 4] { { -99997, 2, 4, 67 }, { 3, -6, -4, 77 }, { -95, 6, -99, -9990 } };
textBox1.Text = recursivemin(arr, 0, Int32.MaxValue).ToString();
}
private static int recursivemin(int[,] arr, int pos, int currentmin)
{
if (pos >= arr.GetLength(0) * arr.GetLength(1))
{
return currentmin;
}
if (arr[pos % arr.GetLength(0), pos / arr.GetLength(0)] < currentmin)
{
currentmin = arr[pos % arr.GetLength(0), pos / arr.GetLength(0)];
}
pos++;
return recursivemin(arr, pos, currentmin);
}
}
}