Advertisement
NurAliya

Практика 6 рим 3 № 17

Sep 28th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. namespace ConsoleApplication1
  5. {
  6.     class ForEachTest
  7.     {
  8.         static void InputArray(out int[,] a)
  9.         {
  10.             Console.Write("Enter count string of massiv: ");
  11.             int n = int.Parse(Console.ReadLine());
  12.             Console.Write("Enter count column of massiv: ");
  13.             int m = int.Parse(Console.ReadLine());
  14.             a = new int[n, m]; // объявление массива
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 for (int j = 0; j < m; j++)
  18.                 {
  19.                     Console.Write("a[{0},{1}]= ", i, j);
  20.                     a[i, j] = int.Parse(Console.ReadLine());
  21.                 }
  22.             }
  23.  
  24.         }
  25.         static string CheckConditions(int[,] a)
  26.         {
  27.             int len = a.GetLength(0);
  28.             for (int i = 0; i < len; i++)
  29.             {
  30.                 int sum = 0;
  31.                 for (int j = 0; j < len; j++)
  32.                 {
  33.                     if (a[i, j] > 0)
  34.                     {
  35.                         sum++;
  36.                     }
  37.                 }
  38.                 if (sum == len)
  39.                 {
  40.                     return "Massiv has a string with positive elements only";
  41.                 }
  42.             }
  43.             return "Massiv hasn't a string with positive elements only";
  44.         }
  45.         static void Main()
  46.         {
  47.             int[,] a;
  48.             InputArray(out a);
  49.             Console.WriteLine(CheckConditions(a));
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement