Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace sztf1labor04
- {
- class Program
- {
- static int[,] GenMap(int n)
- {
- int[,] temp = new int[n, n];
- Random rnd = new Random();
- for (int j = 0; j < n; j++)
- {
- for (int i = 0; i < n; i++)
- {
- temp[j, i] = rnd.Next(0, 1001);
- }
- }
- return temp;
- }
- static void KiMap(ref int[,] t)
- {
- for (int j = 0; j < t.GetLength(0); j++)
- {
- for (int i = 0; i < t.GetLength(1); i++)
- {
- Console.Write(t[j, i] + " ");
- }
- Console.WriteLine();
- }
- }
- static double AVG(ref int[,] t)
- {
- int sum = 0;
- int db = 0;
- for (int i = 0; i < t.GetLength(0); i++)
- {
- for (int j = 0; j < t.GetLength(1); j++)
- {
- db++;
- sum += t[i, j];
- }
- }
- return (double)sum / (double)db;
- }
- static int NumAboveAVG(ref int[,] t)
- {
- double avg = AVG(ref t);
- int db = 0;
- for (int i = 0; i < t.GetLength(0); i++)
- {
- for (int j = 0; j < t.GetLength(1); j++)
- {
- if ((double)t[i, j] < avg)
- {
- db++;
- }
- }
- }
- return db;
- }
- static void Main(string[] args)
- {
- int[,] Térkép = GenMap(3);
- KiMap(ref Térkép);
- Console.WriteLine(AVG(ref Térkép));
- Console.WriteLine(NumAboveAVG(ref Térkép));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment