What am I doing wrong? Two two-dimensional arrays of dimension N * M are given (the elements are random numbers). Display the product of the elements of the specified arrays.

Random ran = new Random(); int[,] m1 = new int[3, 3]; int[,] m2 = new int[3, 3]; int[,] m3 = new int[3, 3]; for (int m = 0; m < 3; m++) { for (int je = 0; je < 3; je++) { for (int k = 0; k < 3; k++) { int sk = 0; sk += m1[m, je] * m2[m, je]; m3[m, je] = sk; } Console.WriteLine(); } } // } Console.WriteLine(); 

    2 answers 2

     static void Main(string[] args) { int[,] m1 = new int[3, 3]; int[,] m2 = new int[3, 3]; int[,] m3 = new int[3, 3]; Random ran = new Random(); // Π—Π°ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ случайными числами for (int m = 0; m < 3; m++) { for (int je = 0; je < 3; je++) { m1[m, je] = ran.Next(10); // ran.Next(максимально допустимоС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅); m2[m, je] = ran.Next(10); } } for (int m = 0; m < 3; m++) { for (int je = 0; je < 3; je++) { m3[m, je] = m1[m, je] * m2[m, je]; // ΠŸΡ€ΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½ΠΈΠ΅ ΠΌΠ°Ρ‚Ρ€ΠΈΡ† } } Console.WriteLine("ΠŸΡ€ΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½ΠΈΠ΅ Π΄Π²ΡƒΠΌΠ΅Ρ€Π½Ρ‹Ρ… ΠΌΠ°Ρ‚Ρ€ΠΈΡ† m1 ΠΈ m2:"); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Console.Write(m3[i, j] + " "); // Π²Ρ‹Π²ΠΎΠ΄ Π² консоль } Console.WriteLine(); } Console.ReadKey(); } 
    • Huge, thanks !!!!!!!! - Maria1233333
    • The man rescued you and didn't even get a plus sign = ( - Zowie
    • And what a plus sign? I am very grateful for the help !!! Thanks again! - Maria1233333

    You do not fill arrays with random data. The arrays are not initialized and you most likely see an error immediately upon startup (if this is Java, as I understood it).
    [added]

     Random ran = new Random(); int[,] m1 = new int[3, 3]; int[,] m2 = new int[3, 3]; int[,] m3 = new int[3, 3]; int sk=0; for (int m = 0; m < 3; m++) { for (int je = 0; je < 3; je++) { m1[m, je]=ran.Next(1000); m2[m, je]=ran.Next(1000); m3[m, je] = m1[m, je] * m2[m, je]; sk+= m3[m, je]; Console.WriteLine(m3[m, je]); } } // } Console.WriteLine(); 

    This is my first experience to write in c #, but it seems to me that it should be something like that. (did not check, because there is no IDE corresponding).
    [/ added]

    • Judging by Console.WriteLine(); This is C #, not Java. - angry
    • not the essence, is not visible array initialization - ReinRaus
    • Yes, this is C sharp and how to fix it ?? - Maria1233333
    • Here is an error in rnd word I do not understand what to replace? - Maria1233333
    • @ Maria1233333, corrected - ReinRaus