Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1;
- using System.Text;
- public class Task20
- {
- public void Run()
- {
- Console.InputEncoding = Encoding.Unicode;
- Console.OutputEncoding = Encoding.Unicode;
- int randomRangeIncludedLowBound = 1;
- int randomRangeExcludedHighBound = 10;
- Random random = new Random();
- int columnsCount = 5;
- int rowsCount = 4;
- int[,] matrix = new int[rowsCount, columnsCount];
- bool canExit = false;
- while ( canExit == false )
- {
- Console.Clear();
- string displayedMatrix = string.Empty;
- int desiredColumnIndex = 0;
- int multiplyOfDesiredColumn = 1;
- int desiredRowIndex = 1;
- int sumOfDesiredRow = 0;
- for ( int i = 0; i < rowsCount; i++ )
- {
- for ( int j = 0; j < columnsCount; j++ )
- {
- matrix[i, j] = random.Next( randomRangeIncludedLowBound, randomRangeExcludedHighBound );
- displayedMatrix = $"{displayedMatrix}{matrix[i, j]} ";
- if ( j == desiredColumnIndex )
- multiplyOfDesiredColumn *= matrix[i, j];
- if ( i == desiredRowIndex )
- sumOfDesiredRow += matrix[i, j];
- }
- displayedMatrix = $"{displayedMatrix}\n";
- }
- displayedMatrix = $"{displayedMatrix}\n";
- Console.WriteLine( displayedMatrix );
- Console.WriteLine( $"Calculations result: \nmultiply of column {desiredColumnIndex} is {multiplyOfDesiredColumn}\n" +
- $"sum of row {desiredRowIndex} is {sumOfDesiredRow}\n" );
- string properlyExitAnswer = "n";
- Console.WriteLine( $"Continue? Enter \'{properlyExitAnswer}\' for exit" );
- string continueAnswer = Console.ReadLine();
- canExit = string.Equals( continueAnswer, properlyExitAnswer );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement