Advertisement
itruf

Sanya 2

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