Question

C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with...

C#

1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with each element representing its column and row value, starting from 1. So the element at the first column and the first row will be 11. If either length is out of the range, simply return a null. For exmaple, if colLength = 5 and rowLength = 4, you will see:

11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
41 42 43 44 45

public static int[][] CreateJaggedMatrix(int rowLength, int colLength)
{
  
}

2.

Given two lengths between 0 and 9, create an rowLength by colLength matrix with each element representing its column and row value, starting from 1. So the element at the first column and the first row will be 11. If either length is out of the range, simply return a null. For exmaple, if colLength = 5 and rowLength = 4, you will see:

11 12 13 14 15
21 22 23 24 25
31 32 33 34 35
41 42 43 44 45

public static int[,] CreateMatrix(int rowLength, int colLength)
{

}

3. Produce a new one-dimensional array that maps all the diagonals from upper-left to lower-right elements. The first element will start from the bottom-left corner of the array. For example, if the value of a is
11 12 13 14
21 22 23 24
31 32 33 34

The new array will be: { 31, 21, 32, 11, 22, 33, 12, 23, 34, 13, 24, 14 }.

public static int[] Diagonals_NWtoSE(int[,] a)
{
  
}

4. generate a rectangular array by specifying the number of rows and the number of columns. A sequence of numbers, starting from a number, of the array will then be populated into the rectangular array in clockwise loops, starting from the top-left corner of the outer loop to the last inner loop. If the row's length or the col's length is invalid, simply return a null.
/// For 8 by 11 array and start = 1, you will have
/// 1 2 3 4 5 6 7 8 9 10 11
/// 34 35 36 37 38 39 40 41 42 43 12
/// 33 60 61 62 63 64 65 66 67 44 13
/// 32 59 78 79 80 81 82 83 68 45 14
/// 31 58 77 88 87 86 85 84 69 46 15
/// 30 57 76 75 74 73 72 71 70 47 16
/// 29 56 55 54 53 52 51 50 49 48 17
/// 28 27 26 25 24 23 22 21 20 19 18

public static int[,] CreateSpiral(int rowLength, int colLength, int start = 1)
{
  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1) Jagged Matrix is a matrix in which each row has different number of columns.

Since in this question each row has same number of columns, so we can use a simple 2-Dimensional array.

public static int[][] CreateJaggedMatrix(int rowLength, int colLength)
{
if ( rowLength <0 || rowLength >9) // If rowLength doesn't fall in range 0-9
return null;
  
if ( colLength <0 || colLength >9) // If colLength doesn't fall in range 0-9
return null;
  
int[, ] intarray = new int[rowLength, colLength]; // 2-Dimensional Array created with given number of //rows and columns
for (int i = 0; i < rowLength; i++)
{
for (int j = 0 ; j< colLength ; j++)
intarray[i, j] = (i+1)*10 + (j+1); //(i+1) & (j+1) bcoz indexing of array starts from 0
// This formula represents when we have to create a 2-digit no.
// For Example, to generate 11 we will write 1*10 + 1

}
return intarray;

}

Answer 2)

public static int[,] CreateMatrix(int rowLength, int colLength)
{

if ( rowLength <0 || rowLength >9)
return null;
  
if ( colLength <0 || colLength >9)
return null;
  
int[, ] intarray = new int[rowLength, colLength]; // 2-Dimensional Array created with given number of //rows and columns
for (int i = 0; i < rowLength; i++)
{
for (int j = 0 ; j< colLength ; j++)
intarray[i, j] = (i+1)*10 + (j+1); //(i+1) & (j+1) bcoz indexing of array starts from 0
// This formula represents when we have to create a 2-digit no.
// For Example, to generate 11 we will write 1*10 + 1

}
return intarray;

}

Answer 4)

public static int[,] CreateSpiral(int rowLength, int colLength, int start = 1)
{ // We will maintain four variables to toggle between rows and columns to achieve the required spiral form.
int i, k = 0, l = 0, m, n;
m = rowLength;
n = colLength;
int [, ] a = new int[m, n];
/* k - starting row index
m - ending row index
l - starting column index
n - ending column index
  i - variable used for iterating through rows in matrix  
*/

while (k < m && l < n)
{
// Storing the first row from the remaining rows
for (i = l; i < n; ++i)
{
a[k, i] = start++;
}
k++;

// Storing the last column from the remaining columns  
for (i = k; i < m; ++i)
{
a[i,n - 1] = start++;
}
n--;

// Storing the last row from the remaining rows */
if ( k < m)
{
for (i = n-1; i >= l; --i)
{
a[m - 1, i] = start++;
}
m--;
}

// Storing the first column from the remaining columns */
if (l < n)
{
for (i = m-1; i >= k; --i)
{
a[i, l] = start++;
}
l++;  
}   
}
return a;
}

public static intl,] CreateSpiral(int rowLength, int colLength, int start 1) // We will maintain four variables to toggle between rows and columns to achieve the required spiral form. int i, k -0, l 0, m, n; mrowLength; ncolLength; int L Janew intlm, n]; /* k -starting row index m ending row index 1 - starting column index n ending column index i - variable used for iterating through rows in matrix while (k < m && 1 < n) // Storing the first row from the remaining rows a[k, i] -start++; // Storing the last column from the remaining columns all,n 1] start++ ; - // Storing the last row from the remaining rows * if(k<m) a[m 1, i] - start++;

Add a comment
Know the answer?
Add Answer to:
C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • These are my instructions: Your data should have been read in from the data file and stored into ...

    These are my instructions: Your data should have been read in from the data file and stored into an array. Next you need to calculate the following and display in a single Message box: Average score Highest score Lowest score Mode of the scores Your program should be written using methods and should be well documented internally and externally. Your output should be displayed using Message boxes. This is the .text file to use with the instructions: 20 21 22...

  • C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand h...

    C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand how to traverse a two dimensional array Code and run a program that processes a two dimensional array Instructions: A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column, sum of the main diagonal, and sum of the reverse diagonal are all the same value. You are to code a program to determine...

  • An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and ...

    An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and 1≤j<l≤n , we have >A[i,j]+a[k,l]≤A[i,l]+A[k,j]> In other words, whenever we pick two rows and two columns of a Monge array and consider the four elements at the intersections of the rows and columns, the sum of the upper-left and lower-right elements is less than or equal to the sum of the lower-left and upper-right elements. For example, the following...

  • Magic Square question for Python

    You have this solution in Java, I am interested in this same solution for Python.One interesting application of two-dimensional arrays is magic squares. A magic square is a square matrix in which the sum of every row, every column, and bothdiagonals is the same. Magic squares have been studied for many years, and there are some particularly famous magic squares. In this exercise you will write code todetermine whether a square is magic.You should find that the first, second, and...

  • Please Help *Urgent* 1 /* */ 2 public class LabFinal 3 { 4 public static void...

    Please Help *Urgent* 1 /* */ 2 public class LabFinal 3 { 4 public static void main(String[] args) { 5 String mesg = "Try out this String."; 6 char[] hold = mesg.toLowerCase().toCharArray(); 7 int p=0; 8 9 System.out.println(forwardSearch(hold,'s')); //output generated 11 10 System.out.println(forwardSearch(hold,'t')); //output generated 0 11 System.out.println(p=forwardSearch(hold,'t',2)); //output generated 6 12 System.out.println(p=forwardSearch(hold,'t',p+1)); //output generated 8 13 System.out.println(p=forwardSearch(hold,'z')); //output generated -1 14 System.out.println(backwardSearch(hold,'s')); //output generated 13 15 System.out.println(backwardSearch(hold,'t')); //output generated 14 16 System.out.println(p=backwardSearch(hold,'t',13)); //output generated 8 17 System.out.println(p=backwardSearch(hold,'t',p-1)); //output generated...

  • 1. Given the following physical addresses and value in memory: add 0 val 9 10 11 12 13 1415161181...

    1. Given the following physical addresses and value in memory: add 0 val 9 10 11 12 13 14151611819 2021 22 23 18 24 20 32 0 40 8 32 245458 10 36 34 3230 40 35 3028 add 24 25 26 27 28 29 30 31 32 33 34 | 35 | 36 37 38 39 40 | 41 | 42 | 43 44 45 46 47 8 40 35 1614 12 12 22 24417 21 23 25 27...

  • Line number 9 contains the code line that declares the result array ( asked in another...

    Line number 9 contains the code line that declares the result array ( asked in another question of this exam). On Line number 11 where col_ contains the correct statement ( asked in another question of this exam) Question: Write the codeline (single line) to compute the matrix multiplication of "frstMatrix" and "scndMatrix". For this question you will write a code line for line number 17 1 package ok4; 2 //This java program multiplies two matrices 3 //represented with two...

  • Game   Point_Differential   Assists   Rebounds   Turnovers   Personal_Fouls 1   15   15   38   11   9 2   36   20   43 &

    Game   Point_Differential   Assists   Rebounds   Turnovers   Personal_Fouls 1   15   15   38   11   9 2   36   20   43   8   13 3   16   21   29   7   13 4   45   22   46   11   11 5   12   11   40   7   22 6   -10   10   31   13   26 7   11   19   45   11   7 8   12   16   32   16   14 9   3   16   27   18   15 10   19   9   34   17   17 11   40   16   41   9   17 12   44   12   29   9   22 13   16  ...

  • Determine how many CH2 and CH3, CH and C (no hydrogen) groups are in the molecule....

    Determine how many CH2 and CH3, CH and C (no hydrogen) groups are in the molecule. and how many proton groups are there. Does the spectra agree with this? Cholesterol in CDC13 Proton spectrum AAA M. T T 40 0.5 5 5,0 4.5 3.5 3.0 25 2.0 1,5 14 0 f1 (ppm) Cholesterol in CDC13 Carbon Spectrum ..demel. 135 130 80 10 50 145 140 125 120 115 110 105 100 95 90 85 70 75 f1 (ppm) 65 60...

  • Complete the following program based on the comments inside. Important note: You are only allowed to...

    Complete the following program based on the comments inside. Important note: You are only allowed to use the new operator in solving this problem. (i.e. Don't use predefined array functions such as append(), concat(), etc. in solving this problem) Important Note 2: Your program should work the same if the sizes of first_array and second_array are changed. (i.e. make use of the .length variable to get the length of the arrays) void setup () { int [] first_array = {11,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT