C# :: Aufgabe #7 :: Lösung #3
15 Lösungen
#7
Übung mehrdimensionales Datenfeld welches aus zufälligen Inhalten besteht darstellen
Anfänger - C#
von Gustl
- 30.07.2012 um 23:37 Uhr
#3
von wladi-g (1310 Punkte)
- 05.06.2014 um 15:04 Uhr
using System;
using System.Windows.Forms;
namespace DatenfeldMehrdimensional
{
public partial class Form1 : Form
{
Random rnd;
int[, ,] arr;
int min = 100;
public Form1()
{
InitializeComponent();
arr = new int[6, 3, 4];
rnd = new Random();
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
textBox1.Text += "( ";
for (int k = 0; k < arr.GetLength(2); k++)
{
arr[i, j, k] = rnd.Next(10, 99);
textBox1.Text += arr[i, j, k].ToString() + " ";
}
textBox1.Text += ") ";
}
textBox1.Text += "\r\n";
}
}
private void button1_Click(object sender, EventArgs e)
{
foreach (int i in arr)
if (i < min)
min = i;
textBox2.Text = "Minimum: " + min.ToString() + ", an Position:\r\n";
for (int i = 0; i < arr.GetLength(0); i++)
for (int j = 0; j < arr.GetLength(1); j++)
for (int k = 0; k < arr.GetLength(2); k++)
if (arr[i, j, k] == min)
textBox2.Text += "Zeile " + i + ", Gruppe " + j + ", Element " + k + "\r\n";
}
}
}
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1
