Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace array
- {
- }
- class MainClass
- {
- public static void Main (string[] args)
- {
- Console.WriteLine ("Hello World!");
- Random rand = new Random ();
- int M, N;
- Console.WriteLine ("M:");
- M = Convert.ToInt32 (Console.ReadLine());
- Console.WriteLine ("N:");
- N = Convert.ToInt32 (Console.ReadLine());
- int[,] Mass = new int[M, N];
- for (int i = 0; i < M; i++) {
- for (int j = 0; j < N; j++) {
- Mass [i, j] = rand.Next (0, 9);
- Console.Write (Mass [i, j].ToString () + " ");
- }
- Console.WriteLine ("");
- }
- int diagonalSumm = countDiag (Mass);
- Console.WriteLine ("Cумма главной диагонали: " + diagonalSumm.ToString ());
- Console.WriteLine ("Строки, сумма элементов которых меньше суммы главной диагонали:");
- for (int i = 0; i < M; i++) {
- int summ = 0;
- for (int j = 0; j < M; j++) {
- summ = summ + Mass [i, j];
- }
- if (summ < diagonalSumm) {
- Console.WriteLine (i.ToString ());
- }
- }
- }
- public static int countDiag(int[,] Mass) {
- if (Mass.GetLength(0) == Mass.GetLength(1)) {
- int diagonalSumm = 0;
- for (int i = 0; i < Mass.GetLength(0); i++) {
- diagonalSumm = diagonalSumm + Mass [i, i];
- }
- return diagonalSumm;
- } else {
- Console.WriteLine("Матрица не квадратна");
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement