Advertisement
sergezhu

Untitled

Apr 30th, 2023
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. namespace ConsoleApp1;
  2.  
  3. using System.Text;
  4.  
  5. public class Task20
  6. {
  7.     public void Run()
  8.     {
  9.         Console.InputEncoding = Encoding.Unicode;
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.  
  12.         int randomRangeIncludedLowBound = 1;
  13.         int randomRangeExcludedHighBound = 10;
  14.         Random random = new Random();
  15.        
  16.         int columnsCount = 5;
  17.         int rowsCount = 4;
  18.         int[,] matrix = new int[rowsCount, columnsCount];
  19.        
  20.         bool canExit = false;
  21.  
  22.         while ( canExit == false )
  23.         {
  24.             Console.Clear();
  25.  
  26.             string displayedMatrix = string.Empty;
  27.  
  28.             int desiredColumnIndex = 0;
  29.             int multiplyOfDesiredColumn = 1;
  30.            
  31.             int desiredRowIndex = 1;
  32.             int sumOfDesiredRow = 0;
  33.  
  34.             for ( int i = 0; i < rowsCount; i++ )
  35.             {
  36.                 for ( int j = 0; j < columnsCount; j++ )
  37.                 {
  38.                     matrix[i, j] = random.Next( randomRangeIncludedLowBound, randomRangeExcludedHighBound );
  39.                     displayedMatrix = $"{displayedMatrix}{matrix[i, j]} ";
  40.  
  41.                     if ( j == desiredColumnIndex )
  42.                         multiplyOfDesiredColumn *= matrix[i, j];
  43.  
  44.                     if ( i == desiredRowIndex )
  45.                         sumOfDesiredRow += matrix[i, j];
  46.                 }
  47.                
  48.                 displayedMatrix = $"{displayedMatrix}\n";
  49.             }
  50.  
  51.             displayedMatrix = $"{displayedMatrix}\n";
  52.  
  53.             Console.WriteLine( displayedMatrix );
  54.             Console.WriteLine( $"Calculations result: \nmultiply of column {desiredColumnIndex} is {multiplyOfDesiredColumn}\n" +
  55.                                $"sum of row {desiredRowIndex} is {sumOfDesiredRow}\n" );
  56.  
  57.             string properlyExitAnswer = "n";
  58.             Console.WriteLine( $"Continue? Enter \'{properlyExitAnswer}\' for exit" );
  59.             string continueAnswer = Console.ReadLine();
  60.  
  61.             canExit = string.Equals( continueAnswer, properlyExitAnswer );
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement