Guest User

Untitled

a guest
Apr 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1.     class Program
  2.     {
  3.         static int getInt(string varName)
  4.         {
  5.             while (true)
  6.             {
  7.                 try
  8.                 {
  9.                     System.Console.Write(varName+" = ");
  10.                     return int.Parse(System.Console.ReadLine());
  11.                 }
  12.                 catch { }
  13.             }
  14.         }
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             int M = getInt("M"),
  19.                 N = getInt("N"),
  20.                 Z = getInt("Z");
  21.  
  22.             var arr = new int[M,N,Z];
  23.             for (int m = 0; m < M; m++)
  24.                 for (int n = 0; n < N; n++)
  25.                     for (int z = 0; z < Z; z++)
  26.                         arr[m, n, z] = getInt(string.Format("arr[{0},{1},{2}]",m,n,z));
  27.             int? min = null, max = null;
  28.             int sum = 0;
  29.             for (int m = 0; m < M; m++)
  30.                 for (int n = 0; n < N; n++)
  31.                     for (int z = 0; z < Z; z++)
  32.                     {
  33.                         if (min == null || arr[m, n, z] < min)
  34.                             min = arr[m, n, z];
  35.                         if (max == null || arr[m, n, z] > max)
  36.                             max = arr[m, n, z];
  37.                         sum += arr[m, n, z];
  38.                     }
  39.             float avr = sum / (float) (M*N*Z);
  40.             System.Console.Write("min = {0}\nmax = {1}\navr = {2}", min, max, avr);
  41.             System.Console.ReadKey();
  42.         }
  43.     }
Add Comment
Please, Sign In to add comment