40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Exercises_C_Sharp.E26_Mehrdimensionale_Arrays
|
|
{
|
|
class Exercise_3
|
|
{
|
|
static int[,] intArray = new int[,]{
|
|
{ 1, 2, 3 },
|
|
{ 3, 4, 5 },
|
|
{ 5, 6, 6 },
|
|
{ 7, 8, 9 }
|
|
};
|
|
public static void Start()
|
|
{
|
|
//Geben Sie das 2-dimensionale Feld auf der Konsole aus. Geben Sie zu jeder Zeile und zu jeder Spalte die jewilige Summe mit aus.
|
|
|
|
//Code START
|
|
int[] sums = new int[intArray.GetLength(1)];
|
|
for (int i = 0; i < intArray.GetLength(0); i++)
|
|
{
|
|
int sum = 0;
|
|
for (int j = 0; j < intArray.GetLength(1); j++)
|
|
{
|
|
Console.Write(intArray[i, j] + " ");
|
|
sum += intArray[i, j];
|
|
sums[j] += intArray[i, j];
|
|
}
|
|
Console.WriteLine(sum);
|
|
}
|
|
foreach (var element in sums)
|
|
Console.Write(element + " ");
|
|
|
|
//Code ENDE
|
|
|
|
}
|
|
|
|
}
|
|
} |