Advertisement
itruf

Sanya

Dec 27th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using System;
  2.  
  3. namespace array
  4. {
  5. class MainClass
  6. {
  7. public static void Main (string[] args)
  8. {
  9. Console.WriteLine ("Hello World!");
  10.  
  11. Random rand = new Random ();
  12. int M, N;
  13.  
  14. Console.WriteLine ("M:");
  15. M = Convert.ToInt32 (Console.ReadLine());
  16.  
  17.  
  18. Console.WriteLine ("N:");
  19. N = Convert.ToInt32 (Console.ReadLine());
  20.  
  21. int[,] Mass = new int[M, N];
  22. for (int i = 0; i < M; i++) {
  23. for (int j = 0; j < N; j++) {
  24. Mass [i, j] = rand.Next (0, 9);
  25. Console.Write (Mass [i, j].ToString () + " ");
  26. }
  27. Console.WriteLine ("");
  28. }
  29.  
  30. //Если квадратная
  31. if (M == N) {
  32. int diagonalSumm = 0;
  33. for (int i = 0; i < M; i++) {
  34. diagonalSumm = diagonalSumm + Mass [i, i];
  35. }
  36.  
  37. Console.WriteLine ("Cумма главной диагонали: " + diagonalSumm.ToString ());
  38.  
  39. Console.WriteLine ("Строки, сумма элементов которых меньше суммы главной диагонали:");
  40.  
  41. for (int i = 0; i < M; i++) {
  42. int summ = 0;
  43. for (int j = 0; j < M; j++) {
  44. summ = summ + Mass [i, j];
  45. }
  46. if (summ < diagonalSumm) {
  47. Console.WriteLine (i.ToString ());
  48. }
  49. }
  50. } else {
  51. Console.WriteLine ("Матрица не квадратная");
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement