Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApplication20
- { class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите количество элементов в массиве a:");
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- int[,] a = new int[n, m];
- int s = 0;
- double max = a[0, 0];
- Random random = new Random();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- a[i, j] = random.Next(-100, 100);
- if (max < a[i, j])
- { max = a[i, j]; }
- else { s += a[i, j];}
- Console.Write("{0,4}", a[i, j]);
- }
- Console.WriteLine();
- }
- Console.WriteLine("max = {0}", max);
- Console.WriteLine("sum = {0}", s);
- Console.ReadKey(true);
- }}}
- if (max < a[i, j])
- {
- max = a[i, j];
- s = 0;
- }
- else if (a[i, j] % 2 != 0)
- {
- s += a[i, j];
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace tstCons
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите количество элементов в массиве a:");
- int n = int.Parse(Console.ReadLine());
- int m = int.Parse(Console.ReadLine());
- int[,] a = new int[n, m];
- int s = 0;
- int max = -100; // присваеваем минимальное возможноме значение
- int maxI = 0, maxJ = 0; // чтобы запомнить координату максимального элемента
- Random random = new Random();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- a[i, j] = random.Next(-100, 100);
- if (max < a[i, j])
- {
- max = a[i, j];
- maxI = i;
- maxJ = j;
- } // ищем максимум и запоминаем его координаты
- Console.Write(a[i, j].ToString() + " ");
- }
- Console.WriteLine();
- }
- bool flag = false; //исключим максимальный элемент
- for (int i = maxI; i < n; i++)
- {
- for (int j = maxJ; j < m; j++)
- {
- if (!flag) // если элемент - максимум, то ничего не делаем
- {
- flag = true;
- continue;
- }
- if (a[i,j]%2 != 0) s += a[i, j]; // проверяем элемент на четность и увеличеваем счетчик
- }
- }
- Console.WriteLine("max = {0}", max);
- Console.WriteLine("sum = {0}", s);
- Console.ReadKey(true);
- }
- }
- }
Add Comment
Please, Sign In to add comment