Advertisement
myname0

практикум6_IV_13

Oct 14th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1.    static int[,] Create(int n)
  2.         {
  3.             Console.WriteLine("Enter the array: ");
  4.             int[,] mas = new int[n, n];
  5.             String enterString;
  6.             String[] massiveString;
  7.             for (int i = 0; i < n; i++)
  8.             {
  9.                 enterString = Console.ReadLine();
  10.                 massiveString = enterString.Split(new Char[] { ' ' });
  11.                 for (int j = 0; j < n; j++)
  12.                 {
  13.                     mas[i, j] = int.Parse(massiveString[j]);
  14.                 }
  15.             }
  16.             return mas;
  17.         }
  18.         static void Print(int n, int [] mas)
  19.         {
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                         Console.Write("{0} ", mas[i]);
  23.             }
  24.         }
  25.  
  26.         static int[] Change(int n, int [,] mas)
  27.         {
  28.             bool flag;
  29.             int [] chMas = new int [n];
  30.             for (int i = 0; i < n; i++)
  31.             {
  32.                 flag = true;
  33.                 for (int j = 0; j < n; j++)
  34.                 {
  35.                     if (mas[i, j] < 0)
  36.                     {
  37.                         chMas[i] = j;
  38.                         flag = false;
  39.                         break;
  40.                     }
  41.                 }
  42.                 if (flag) chMas[i] = -1;
  43.             }
  44.             return chMas;
  45.         }
  46.         static void Main(string[] args)
  47.        
  48.        {
  49.            Console.Write("Enter n: ");
  50.            int n = int.Parse(Console.ReadLine());
  51.            int [,] mas = new int [n,n];
  52.            mas = Create(n);
  53.            int [] changeMas = new int [n];
  54.            changeMas = Change(n, mas);
  55.            Console.WriteLine("The output of the array:");
  56.            Print(n, changeMas);
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement