Find the maximum element in each line of a two-dimensional array and replace it with "."
Random ran = new Random(); int[,] myArr = new int[4, 5]; for (int i = 0; i <4; i++) { for (int j = 1; j <5; j++) { myArr[i, j] = ran.Next(1, 99); } } Find the maximum element in each line of a two-dimensional array and replace it with "."
Random ran = new Random(); int[,] myArr = new int[4, 5]; for (int i = 0; i <4; i++) { for (int j = 1; j <5; j++) { myArr[i, j] = ran.Next(1, 99); } } Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
it doesn't work like this in C # (although you can write it in some other languages).
C # language with static typing https://ru.wikipedia.org/wiki/Static_tipization
In your case, you cannot change the type of your array while the program is running.
int[,] myArr = new int[4, 5]; In this line, on the left, you said (for simplicity) that the variable myArr is of type int []. Now you can add only numbers and fix it.
You have given very little description and may not have read how to ask questions. You need to ask a specific question, because at the moment it sounds like “I haven’t done anything, do it for me” (therefore, you are given minuses, not because the question is bad).
To answer you, ask a specific question. In this case, it sounds like "How do I insert a character into an array of numbers?"
The fact is that this is a knowledge archive forum consisting of questions. The question and answer should contain a tutorial page. Imagine that you are writing an introduction to the topic of the lesson. Details are written in the answers, and in the comments you discuss with colleagues how best to write.
Hint how to make
If you issue a question correctly, I will answer it. While empty.
In order to be able to place one non-integer value into an array, you can use int?[,] Instead of the type int[,] int?[,] . In this case, the array can be placed null , which, in my opinion, is ideally suited for the described task. And already when outputting instead of null, output a dot.
An example of how to replace the element a[2,3] : https://ideone.com/TvZEND
using System; public class Test { public static void Main() { Random ran = new Random(); int n = 4, m = 5; int?[,] a = new int?[n, m]; for (int q=0; q<n; ++q) for (int w=0; w<m; ++w) a[q, w] = ran.Next(0, 9); a[2, 3] = null; for (int q=0; q<n; ++q) { for (int w=0; w<m; ++w) Console.Write("{0} ", a[q, w]?.ToString() ?? "."); Console.WriteLine(); } } } int maxindex=0, max=myArr[i, 0]; for (int i = 0; i <4; i++) { for (int j = 1; j <5; j++) { if(myArr[i, j]>max) { max=myArr[i, j]; maxindex=j; } myArr[i, maxindex]=10; } Source: https://ru.stackoverflow.com/questions/736184/
All Articles