Created
April 25, 2018 11:37
-
-
Save kodo-pp/f34a65ffa31038fdb87bf0aa8e6b60cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Variant52 | |
{ | |
class Program | |
{ | |
const int N = 4; | |
const int M = 5; | |
static void Main(string[] args) | |
{ | |
int[,] mat = new int[N,M] {{7, 2, 8, -3, 5}, | |
{1, 4, -7, 2, 6}, | |
{1, -7, -4, 7, 9}, | |
{9, 4, -8, -2, 1}}; | |
Console.WriteLine("Исходный двумерный массив:"); | |
for (int i = 0; i < N; i++) | |
{ | |
for (int j = 0; j < M; j++) | |
{ | |
Console.Write("{0,3}", mat[i,j]); | |
} | |
Console.WriteLine(); | |
} | |
Console.WriteLine("Введите номер строки"); | |
int L = int.Parse(Console.ReadLine()) - 1; | |
if (L < 0 || L >= N) | |
{ | |
Console.WriteLine("Введена неверная строка"); | |
return; | |
} | |
int sum = 0; | |
for (int j = 0; j < M; j++) | |
{ | |
sum += mat[L, j]; | |
} | |
double avg = (double)sum / M; | |
int rsum = 0; | |
for (int j = 0; j < M; j++) | |
{ | |
if (mat[L, j] % 2 == 0 && mat[L, j] < avg) | |
{ | |
rsum += mat[L, j]; | |
} | |
} | |
Console.WriteLine("Среднее: {0:f3}", avg); | |
Console.WriteLine("Искомая сумма: {0}", rsum); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment