E26 Ex 3 - 6

This commit is contained in:
Sebastian Schüler 2025-09-29 15:34:09 +02:00
parent a6946a9270
commit 098cd0697f
4 changed files with 34 additions and 9 deletions

View File

@ -21,7 +21,13 @@ namespace Exercises_C_Sharp.E26_Mehrdimensionale_Arrays
static int[,] ReverseArray(int[,] arr)
{
//Code START
return new int[0,0];
int[,] tempArr = new int[arr.GetLength(1), arr.GetLength(0)];
for (int i = 0; i < arr.GetLength(0); i++)
for (int j = 0; j < arr.GetLength(1); j++)
tempArr[j, i] = arr[i, j];
return tempArr;
//Code ENDE
}
@ -29,7 +35,14 @@ namespace Exercises_C_Sharp.E26_Mehrdimensionale_Arrays
static void ShowArray(int[,] arr)
{
//Code START
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
Console.Write(arr[i, j] + "\t");
Console.WriteLine();
}
Console.WriteLine("----------------");
//Code ENDE
}

View File

@ -25,7 +25,12 @@ namespace Exercises_C_Sharp.E26_Mehrdimensionale_Arrays
static int[,] RemoveEven(int[,] arr)
{
//Code START
return new int[0,0];
for (int i = 0; i < arr.GetLength(0); i++)
for (int j = 0; j < arr.GetLength(1); j++)
if (arr[i, j] % 2 == 0)
arr[i, j] = -1;
return arr;
//Code ENDE
}
@ -33,7 +38,12 @@ namespace Exercises_C_Sharp.E26_Mehrdimensionale_Arrays
static int[,] RemoveOdd(int[,] arr)
{
//Code START
return new int[0,0];
for (int i = 0; i < arr.GetLength(0); i++)
for (int j = 0; j < arr.GetLength(1); j++)
if (arr[i, j] % 2 != 0)
arr[i, j] = -1;
return arr;
//Code ENDE
}
}

View File

@ -13,12 +13,14 @@ namespace Exercises_C_Sharp.E26_Mehrdimensionale_Arrays
//Lassen Sie den Nutzer das zweidimensionale Array 'stringArray' mit (9, jeweils eine pro Feld) Eingaben befüllen
//Code START
for (int i = 0; i < stringArray.GetLength(0); i++)
for (int j = 0; j < stringArray.GetLength(1); j++)
stringArray[i, j] = Console.ReadLine() ?? "";
//Code ENDE
//Überprüfung:
foreach(var element in stringArray)
Console.Write(element + " - ");
//Überprüfung:
foreach (var element in stringArray)
Console.Write(element + " - ");
}
}

View File

@ -1,2 +1,2 @@
2
3
25