Question

In: Computer Science

Provide code samples for the following in C#a. Declare a two-dimensional array of integers names...

Provide code samples for the following in C#

a. Declare a two-dimensional array of integers names intArray17.

b. Create a loop to calculate the sum of every element in the first column.

c. Create a loop to calculate the sum of every element in the array.

Solutions

Expert Solution

The code is commented as required. Variables are named accordingly.

I have made the code in online ide.

Change the name of namespace accordingly to make it run in your ide.

Code:

//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{

public class Program
{

public static void Main(string[] args)
{

//Your code goes here
//(a)
int[,] intArray17 = new int[3,2]{{1,2},{3,4},{5,6}}; //Declaring 2d array of size 3*2
//(b)
int sum_first_column=0;//Initializing sum of first column with 0
for(int i=0;i<3;i++){

sum_first_column+=intArray17[i,0];//Adding ith element of first column to required sum

}
Console.WriteLine("The sum of every elemnet in first column is: "+sum_first_column);
//(c)
int sum=0;//Initializing sum of first column with 0
for(int i=0;i<3;i++){

for(int j=0;j<2;j++)

sum+=intArray17[i,j];//Adding (i,j) element to required sum

}
Console.WriteLine("The sum of every elemnet is: "+sum);

}

}

}

Code screenshot and output:


Related Solutions

In C# - Provide code samples for the following: Declare a two-dimensional array of integers names...
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.
1.Declare a two-dimensional array of Strings namedchessboard.
1. Declare a two-dimensional array of Strings named chessboard.2. Declare a two-dimensional array of integers named tictactoe.3. Declare and create a two-dimensional array of chars,tictactoe, with 3 rows, each with 3 elements.4. Create a two-dimensional array of ints, plan, with 2 rows, and and 3 columns and initialize the first row to 8, 20, 50 and the second row to 12, 30, 75. Use member initializer syntax.
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
C++ please 1. Randomly assign integers in the range of 1-100 to a two-dimensional array. Write...
C++ please 1. Randomly assign integers in the range of 1-100 to a two-dimensional array. Write a program that finds the average value of the rows and the average value of the columns. Display the averages. 2. Create an array of randomly generated numbers in any range. Write a function that takes the array as an argument and returns an array that consists of only the even numbers in the original array. Use the function in a program. 3. Create...
Complete the following C# code that declares an array of 7 integers. The application allows the...
Complete the following C# code that declares an array of 7 integers. The application allows the user three options: l. to view the elements of array in reverse order, from the last to first position, 2. to choose a specific position to view, 3. quit the program
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt the user for 6 integer values and store them in arr. Prompt the user for a target integer target. Search for targetin arr. If targetis found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message “the element target not found” will be printed...
(c++ code) A theatre seating chart is implemented as a two-dimensional array of ticket prices, like...
(c++ code) A theatre seating chart is implemented as a two-dimensional array of ticket prices, like this:                 AISLE ROW      1           2             3             4             5             6             7             8             9              10 -------------------------------------------------------------------------------------------------------------- 10           10           10           10           10           10           10           10           10           10           10 9             10           10           10           10           10           10           10           10           10           10 8             10           10           10           10           10           10           10           10           10           10 7             10           10           20           20           20           20           20           20           10           10 6             10           10           20           20          ...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
Write a program in c++ to do the following : (1) Declare an array a of...
Write a program in c++ to do the following : (1) Declare an array a of size 10 and three pointer variables p, q, and v. (2) Write a loop to fill array a with values 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (3) write following statement: p= &a[2]; q = &a[5]; i = *q - *p; cout<<“The value of i is”<< i; i = *p - *q; cout<<“The value of i is %d”<< i; 4) assign...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT