Sum The Values On A Diagonal of A 3x3x3 Matrix
Sum The Values On A Diagonal of A 3x3x3 Matrix
using System;
class Average {
static void Main() {
int[] nums = new int[10];
int avg = 0;
nums[0] = 99;
nums[1] = 10;
nums[2] = 100;
nums[3] = 18;
nums[4] = 78;
nums[5] = 23;
nums[6] = 63;
nums[7] = 9;
nums[8] = 87;
nums[9] = 49;
for(int i=0; i < 10; i++)
avg = avg + nums[i];
avg = avg / 10;
Console.WriteLine("Average: " + avg);
}
}
int[] nums;
nums = new int[] { 99, 10, 100, 18, 78, 23,63, 9, 87, 49 };
// Reverse an array.
using System;
class RevCopy {
static void Main() {
int i,j;
int[] nums1 = new int[10];
int[] nums2 = new int[10];
Console.WriteLine();
using System;
class Jagged {
static void Main() {
var jagged = new[] {
new[] { 1, 2, 3, 4 },
new[] { 9, 8, 7 },
new[] { 11, 12, 13, 14, 15 }
};
for(int j = 0; j < jagged.Length; j++) {
for(int i=0; i < jagged[j].Length; i++)
Console.Write(jagged[j][i] + " ");
Console.WriteLine();
}
}
}
The program produces the following output:
1 2 3 4
9 8 7
11 12 13 14 15