Advertisement
growhack

Task with summ and multiply

Mar 31st, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Summ_and_multiply
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int rows, columns;
  10.             Random rand = new Random();
  11.             int summ = 0, multiply = 1;
  12.             Console.WriteLine("Добро пожаловать, введите размерность матрицы, после чего она заполнится случайными числами и произведет расчеты: ");
  13.             Console.Write("Количество строк - ");
  14.             rows = Convert.ToInt32(Console.ReadLine());
  15.             Console.Write("Количество столбцов - ");
  16.             columns = Convert.ToInt32(Console.ReadLine());
  17.             int[,] array = new int[rows, columns];
  18.             for (int i = 0; i < array.GetLength(0);i++)
  19.             {
  20.                 for( int j = 0; j < array.GetLength(1); j++)
  21.                 {
  22.                     array[i, j] = rand.Next(0, 100);
  23.                     Console.Write(array[i, j] + " ");
  24.                 }
  25.                 Console.WriteLine();
  26.             }
  27.             for (int i = 0; i < array.GetLength(0); i++)
  28.             {
  29.                 for (int j = 0; j < array.GetLength(1); j++)
  30.                 {
  31.                     if( i == 1)
  32.                     {
  33.                         summ += array[i, j];
  34.                     }
  35.                     if(j == 0)
  36.                     {
  37.                         multiply *= array[i, j];
  38.                     }      
  39.                 }
  40.             }
  41.             Console.WriteLine("\nСумма второй строки равна - " + summ + "\nУмножение первого столбца равно - " + multiply);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement