In: Computer Science
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names intArray17. Create a loop to calculate the sum of every element in the first column. Create a loop to calculate the sum of every element in the array.
Please give the thumbs up, if it is helpful for you!!. Let me know if you have any doubts.
using System;
public class Test
{
public static void Main()
{
int[,] intArray17 = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, {
7, 8 } };
int first_col_sum=0;
int total_sum=0;
for(int i = 0; i < 4; i++){
first_col_sum+=intArray17[i,0];
}
Console.WriteLine("sum of every element in the first column:
"+first_col_sum);
for(int i = 0; i < 4; i++){
for(int j=0;j<2;j++){
total_sum+=intArray17[i,j];
}
}
Console.WriteLine("Sum of every element in the array:
"+total_sum);
}
}
Code and output: