Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1;
- using System.Text;
- public class Task21
- {
- public void Run()
- {
- Console.InputEncoding = Encoding.Unicode;
- Console.OutputEncoding = Encoding.Unicode;
- int randomRangeIncludedLowBound = 1;
- int randomRangeExcludedHighBound = 10;
- Random random = new Random();
- int columnsCount = 10;
- int rowsCount = 10;
- int[,] matrix = new int[rowsCount, columnsCount];
- int maxElementChangedValue = 0;
- bool canExit = false;
- while ( canExit == false )
- {
- Console.Clear();
- int maxElement = int.MinValue;
- string displayedMatrix = string.Empty;
- 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 ( matrix[i, j] > maxElement )
- maxElement = matrix[i, j];
- }
- displayedMatrix = $"{displayedMatrix}\n";
- }
- displayedMatrix = $"{displayedMatrix}\n";
- Console.WriteLine("Source matrix:");
- Console.WriteLine( displayedMatrix );
- displayedMatrix = string.Empty;
- for ( int i = 0; i < rowsCount; i++ )
- {
- for ( int j = 0; j < columnsCount; j++ )
- {
- if ( matrix[i, j] == maxElement )
- matrix[i, j] = maxElementChangedValue;
- displayedMatrix = $"{displayedMatrix}{matrix[i, j]} ";
- }
- displayedMatrix = $"{displayedMatrix}\n";
- }
- displayedMatrix = $"{displayedMatrix}\n";
- Console.WriteLine( $"Matrix after swap of max element ({maxElement}) to {maxElementChangedValue}:" );
- Console.WriteLine( displayedMatrix );
- 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