Вопрос по массиву | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Вопрос по массиву

Как узнать какие переменные в массиве loca находятся рядом с переменной loca[x, y]? То есть если loca[x, y]=5 (x=5,y=5) нужно узнать loca[4,5] loca[6,5] loca[5,4] loca[5,6] Спасибо заранее за ответ. https://code.sololearn.com/ctpg0WM9Nq7Q/?ref=app

6th Mar 2019, 1:24 PM
Андрей Бабурин
Андрей Бабурин - avatar
8 Antworten
+ 1
class Program { static void Main(string[] args) {      int x = 5; int y = 5; int [,] loca = new int[11, 11]; for (int i = 0; i < 11; i++)             {      for (int j = 0; j < 11; j++) { if(1 < i & i < 9 ) { loca[i,2] = 5; loca[i,8] = 5; if(1 < j & j < 9 ) { loca[2,j] = 5; loca[8,j] = 5; } } loca [5,j] = 5; loca [i,5] = 5; Console.Write("{0}\t", loca[i,j]); } Console.WriteLine(); } } }
6th Mar 2019, 8:02 PM
Андрей Бабурин
Андрей Бабурин - avatar
+ 1
Is this what you are looking for ? https://code.sololearn.com/c3m5w7arcFF0
6th Mar 2019, 10:25 PM
sneeze
sneeze - avatar
+ 1
Мне нужно, подобие этого когда, но управление не с клавиатуры https://code.sololearn.com/cFTr7Lq8zh5X/?ref=app
8th Mar 2019, 11:19 AM
Андрей Бабурин
Андрей Бабурин - avatar
0
Pushing it through google-translate didn't really solve the issue. Could you please just copy the exact part of the code from the link you're struggling with? Maybe I can than figure out the question. looking at the difficulty level of the code, I should be able to do that. For starters, what's the thing about x en y? Look in your error window: The variable 'x' is assigned but its value is never used The variable 'y' is assigned but its value is never used Meaning give x the value of 2000000 en y the value of 1, and the outcome will be exactly the same. int x = 5; int y = 5; Is bad code, because it serves no meaning. Bluntly said, for int [,] loca = new int[11, 11]; the variables x,y (and their value) are totally irrelevant.
6th Mar 2019, 7:03 PM
[No Name]
0
loca[5, j] = 5; loca[i, 5] = 5; these two lines determine the value for all 4 members of int array: loca[4,5] loca[6,5] loca[5,4] loca[5,6] In all those four cases = 5.
6th Mar 2019, 7:10 PM
[No Name]
0
This code is difficult for the sololearn playground You are not allowed to use Console.Clear; you are also not allowed to use Console.ReadKey(true); please use bracket in you for loop for (int y = 0; y < 5; y++) { for (int x = 0; x < 7; x++) { putCh(map[y, x], y, x); }} It might work but it is bad practice. Can you run it in Visual studio ?
8th Mar 2019, 9:06 PM
sneeze
sneeze - avatar
0
Float int double omвет
17th Dec 2019, 7:47 AM
Кркнн Поггр
0
Можно ответ общий Sololearn
17th Dec 2019, 7:48 AM
Кркнн Поггр