Advertisement
Nikitka_36

9.8 function

Nov 24th, 2014
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace _9._8
  5. {
  6.     class Program
  7.     {
  8.         static void printMass(int[,] mas, int n)
  9.         {
  10.             for (int i = 0; i < n; i++)
  11.             {
  12.                 for (int j = 0; j < n; j++)
  13.                     Console.Write(mas[i, j] + "  ");
  14.                 Console.WriteLine();
  15.             }
  16.         }
  17.  
  18.         static void swapMas(int[,] mas, int n)
  19.         {
  20.             for (int i = 0; i < n; i++)
  21.                 for (int j = 0; j < n; j++)
  22.                     if (j >= i)
  23.                         mas[i, j] = 0;
  24.         }
  25.  
  26.         static void Main()
  27.         {
  28.             Console.WriteLine("Введи размер n");
  29.             int n = int.Parse(Console.ReadLine());
  30.  
  31.             Random rand = new Random();
  32.             int[,] array = new int[n, n];
  33.  
  34.             //Создание массива
  35.             for (int i = 0; i < n; i++)
  36.                 for (int j = 0; j < n; j++)
  37.                     array[i, j] = rand.Next(-5, 25);
  38.  
  39.             //Вывод начального массива
  40.             Console.WriteLine("\nМассив:");
  41.             printMass(array, n);
  42.  
  43.             //Замена эл-тов массив
  44.             swapMas(array, n);
  45.  
  46.             //Вывод замененного массива
  47.             Console.WriteLine("\n\nЗамененный Массив:");
  48.             printMass(array, n);
  49.  
  50.             Console.ReadKey();
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement