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); } } 

Closed due to the fact that the essence of the issue is incomprehensible by the participants iksuy , Vladimir Martyanov , MihailPw , Pavel Mayorov , Eugene Krivenja Oct 27 '17 at 14:27

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 .

    3 answers 3

    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.

    • Thank you for explaining my mistake in formulating the question. The challenge is to create a two-dimensional array of integers, and replace each maximal element with a ".". I already understood my mistake. At the moment, there is a question in another, how to replace the maximum elements of an array and output a new array. - KolyaOlya
    • @Yaroslav Here add while this all in a question. If there are any clarifications, just write UPD (as many do) - Arantler
    • @Yaroslav I prepared an answer, correct the question and I will update the answer. - Arantler

    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; } 
      • every time you go through the first cycle to create variables? Isn't it easier to just reset them than to create them n times? - alexoander
      • I see no problems. - HasmikGaryaka
      • 2
        um - well, ok. It's just a bad approach when the dimension of the array increases. - alexoander
      • No, not bad. - HasmikGaryaka
      • one
        And to convince the teacher that the author of the question wrote all this professional code (I’m talking about other answers). - HasmikGaryaka