Переписать код заполнения массива с C++ на C#
Формулировка задачи:
Приветствую! Помогите транслировать код C++ на C#! Заранее спасибо!
Листинг программы
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int storona, random;
- cout << "Storona kvadrata" << endl;
- cin >> storona;
- //for(int i=0;i<100;i++)cout<<rand()%16+1<<" ";
- int shulte[storona][storona];
- for (int i=0;i<storona;i++) //ÝëåìåГ*ГІГ» Г¬Г*Г±Г±ГЁГўГ* Г*óëè
- for(int j=0;j<storona;j++)
- shulte[i][j]=0;
- for(int step=1;step<=storona*storona;)
- { int i=rand()%storona;
- int j=rand()%storona;
- if(shulte[i][j]==0)
- {shulte[i][j]=step;
- step++;
- }
- }
- for (int i=0;i<storona;i++) //Âûâîä
- {
- for(int j=0;j<storona;j++)
- cout << shulte[i][j]<< " ";
- cout << endl;
- }
- }
Решение задачи: «Переписать код заполнения массива с C++ на C#»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace TranslatedCode
- {
- public class FromCPlusPlusToCSharp
- {
- private static readonly Random Generator = new Random();
- public static void Main(string[] args)
- {
- int side = 0; // storona
- Console.Write("Введите сторону квадрата: ");
- string sideValue = Console.ReadLine();
- if (int.TryParse(sideValue, out side))
- {
- int[][] shulte = new int[side][];
- for (int index = 0; index < side; ++index)
- {
- shulte[index] = new int[side];
- }
- for (int step = 1; step < side * side; )
- {
- int i = Generator.Next() % side;
- int j = Generator.Next() % side;
- if (shulte[i][j] == 0)
- {
- shulte[i][j] = step++;
- }
- }
- for (int i = 0; i < side; ++i)
- {
- for (int j = 0; j < side; ++j)
- {
- Console.Write(shulte[i][j]); Console.Write(" ");
- }
- Console.WriteLine();
- }
- }
- else
- {
- Console.WriteLine("Некорректный ввод :)");
- }
- Console.ReadLine();
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д