Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Введите количество NxM элементов матрицы: ");
  14. int N = 0;
  15. int M = 0;
  16.  
  17. string str = Console.ReadLine();
  18. string stl = Console.ReadLine();
  19. N = int.Parse(str);
  20. M = int.Parse(stl);
  21.  
  22.  
  23. Console.WriteLine("Исходная матрица: ");
  24. Console.WriteLine();
  25. int[,] sample = new int[N, M];
  26. Random rnd = new Random();
  27.  
  28. for (int i = 0; i < N; i++)
  29. {
  30. for (int j = 0; j < M; j++)
  31. {
  32. sample[i, j] = rnd.Next(1, 100); // заполнение матрицы случайными числами
  33. Console.Write(sample[i, j] + " \t ");
  34. }
  35. Console.WriteLine();
  36. }
  37. int[,] trans = new int[M, N];
  38. Console.WriteLine();
  39. Console.WriteLine("Транспонированная матрица: ");
  40. Console.WriteLine();
  41. for (int i = 0; i < M; i++)
  42. {
  43. for (int j = 0; j < N; j++)
  44. {
  45. trans[i, j] = sample[j, i];
  46. Console.Write(trans[i, j] + " \t ");
  47. }
  48. Console.WriteLine();
  49. }
  50. Console.ReadLine();
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement