- prepare a form which accepts 2 numeric positive nos. On clicking generate button, a 2 dimension array of 10 x 10 size will completely filled up with random numbers between those 2 user inputted numbers.
You will print the entire matrix on screen in 10 rows by 10 cols using a function.
There will be one more button called transpose. When user clicks on this button, entire matrix will be transposed. i.e. the all the data elements in rows will be interchanged with columns. After transpose, it will get printed below again. Both print should be visible to users.
public void Button1_Click(object sender, EventArgs e)
{
int intLL = Convert.ToInt32(TextBox1.Text);
int intUL = Convert.ToInt32(TextBox2.Text);
int[,] arr = new int[size, size];
for (int row =0; row < size;row++)
{
for(int col=0;col<size;col++)
{
arr[row, col] = r.Next(intLL,intUL);
//Response.Output.Write(arr[row,col]+TextBox1.Text+TextBox2.Text+" ");
Response.Output.Write(arr[row, col] + " ");
}
Response.Write(" </br>");
}
}
public void Button2_Click(object sender, EventArgs e)
{
}
i get the answer how to generate matrix with random values but on button_2 click event how i get transpose of matrix to display it on same screen
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Actually you are hardcoding the minimun and maximun values of your Random.Next call.
Just check what the user entered in the textboxes and use that values instead. After doing that you could do your traspoosing logic.
Something similar to:
int minValue = 0;
int maxValue = 0;
if (!Int.TryParse(tbMinimunValue, out minValue) || !Int.TryParse(tbMaximunValue, out maxValue))
{
Response.Write("Please enter numbers");
return;
}
// TODO: Add aditional checks like checking min < max, and min and max are positive values
Random r = new Random();
int size = 10;
int[,] arr = new int[size, size];
for (int i = 0; i < size;i++)
{
for(int j=0;j<size;j++)
{
arr[i, j] = r.Next(minValue, maxValue);
Response.Output.Write(arr[i,j]+" ");
}
Response.Write(" </br>");
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0